• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2030
  • Last Modified:

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...
0
gaugeta
Asked:
gaugeta
1 Solution
 
cmalakarCommented:
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%>" />
0
 
cmalakarCommented:
Or.. you can try with the following correct one..

out.println("<input type=\"hidden\" name=\"distVal\" value=\"" + distVal  + " \"/> ");
0
 
gaugetaAuthor Commented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Sathish David Kumar NCommented:
>>>>>>>>
out.println("<input type=\"hidden\" name=\"distVal\" value=<%=distVal%>>");

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

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

is in ?


0
 
cmalakarCommented:
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.
0
 
gaugetaAuthor Commented:
@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...
0
 
cmalakarCommented:
Set the value as attribute, as I said above
0
 
mrcoffee365Commented:
>>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.
0
 
gaugetaAuthor Commented:
@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...
0
 
cmalakarCommented:
>>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.

If you are forwarding the request, you can have setAttribute() in check.jsp and getAttribute() in Edit.jsp.


Otherwise, if you want to use request.getParameter in check.jsp, you can also do this.
Change your request.getRequestDispatcher() to following and try

>>request.getRequestDispatcher("Edit.jsp?" + "distVal=" + distVal).forward(request, response);
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now