views:

146

answers:

1

I need a hidden input to contain the value passed by the querystring via a JSP's URL.

The URL looks like... http://nowhere.com/myapp/blah.jsp?key=12345

The JSP looks like...

<html>
<body>
<input id="key" type="hidden" value="<%=request.getParameter('key')%>" />
</body>
</html>

This causes a 500 error...

SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 3 in the jsp file: /myapp/blah.jsp
Invalid character constant
1: <html>
2: <body>
3: <input id="key" type="hidden" value="<%=request.getParameter('key')%>" />
4: </body>
5: </html>
A: 

It is the quotes. Java interprets the single quote to mean a character rather than a string.

Switch the quotes...

<input id='key' type='hidden' value='<%=request.getParameter("key")%>' />

...and it works.

dacracot