Link to home
Start Free TrialLog in
Avatar of GAUTAM
GAUTAMFlag for United States of America

asked on

String literal is not properly closed by a double-quote IN JSP

Hi experts...
I have an html tag embedded in a out.print statement and i've tried all permutations but am getting an error as String literal is not properly closed by a double-quote
This is my code:
out.println("<input type=\"hidden\" name=\"distVal\" value=<%=distVal%>>");
Please help...
Avatar of cmalakar
cmalakar
Flag of India image

If it is in JSP, then you dont need to do out.println for the above statement.. you can directly write the following statement instead of out.println.

<input type="hidden" name="distVal" value="<%=distVal%>" />
Or.. you can try with the following correct one..

out.println("<input type=\"hidden\" name=\"distVal\" value=\"" + distVal  + " \"/> ");
Avatar of GAUTAM

ASKER

Its still not working.
Actually i am trying to do a request.getParameter(distVal) in the next page after using
request.getRequestDispatcher("Edit.jsp").forward(request, response);
Is this suppose to work.
Avatar of Sathish David  Kumar N
>>>>>>>>
out.println("<input type=\"hidden\" name=\"distVal\" value=<%=distVal%>>");

change this to
<input type="text" name="distVal" value="<%=distVal%>" />
Does the compilation error gone ?

Which page this line out.println("<input type=\"hidden\" name=\"distVal\" value=\"" + distVal  + " \"/> ");

is in ?


if you are using request dispatcher forward..

then before dispatching you need to set the value, as attribute using following statement.

request.setAttribute("distVal", distVal);

and in the jsp where you are doing request.getParameter, use request.getAttribute("distVal").

That should do the trick.
Avatar of GAUTAM

ASKER

@cmalakar:out.println("<input type=\"hidden\" name=\"distVal\" value=\"" + distVal  + " \"/> "); is in a page known as check.jsp.Here i am setting this hidden type tag because if some error occurs in validation i have to repopulate the values in Edit.jsp which i am forwarding.
It's somehow not accepting this.
previously a page known as welcome.jsp also set this hidden tag in the same form with the same name.
Please help...
Set the value as attribute, as I said above
>>Actually i am trying to do a request.getParameter(distVal) in the next page after using
>>request.getRequestDispatcher("Edit.jsp").forward(request, response);

Yes, if you forward the page, all the request parameters are forwarded as well.

I'm assuming that you're not having compile errors any more, and now you're saying that you don't get a value for the parameter "distVal"?  If that's the case, then you're probably not setting a value.  If a form variable doesn't have a value -- if distVal is empty, then it won't get sent to the server by the browser.

If you're still getting compile errors, then follow cmalakar's advise in the first post.
Avatar of GAUTAM

ASKER

@cmalakar:I cannot use the setAttribute() because in one page i use request.getParameter() in one of the pages.So it causes a conflict.
@mrcoffee365:And i had a doubt that can we have parameteres set in request scope with the same name???
Please help...
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial