Question

I am trying to store the value in session, but it shows me a "string doesn't close properly" error.

I am using this code for storing the value:

<% session.setAttribute("emailvalue",request.getParameter("<%=request.getQueryString() %>"));
               String str=(String)session.getAttribute("emailvalue"); %>

Is it the right systax or not?

Was it helpful?

Solution

Instead of

<% session.setAttribute("emailvalue",request.getParameter("<%=request.getQueryString() %>"));String str=(String)session.getAttribute("emailvalue"); %>

store the value obtained from request.getQueryString() in another variable. The code you have has a jsp systemout tag <%=...%> inside another jsp java tag <%...%> which is not supported by the jsp compiler.

Instead make the code simpler to make it work like the following

<% String queryString = request.getQueryString(); session.setAttribute("emailvalue",queryString ); String str=(String)session.getAttribute("emailvalue");%>

OTHER TIPS

You're already inside a scriptlet, so there's no need to use <%= once again to be able to get a Java String:

<% session.setAttribute("emailvalue", request.getQueryString());
   String str = (String) session.getAttribute("emailvalue"); %>

Calling request.getParameter(request.getQueryString()) doesn't make any sense either.

And finally, you shouldn't use scriptlets. Use the JSP EL and the JSTL:

<c:set var="emailValue" value="${pageContext.request.queryString}" scope="session"/>

Or even better, do that in the controller (i.e. a servlet or action of your preferred MVC framework that dispatches to the JSP), as it doesn't seem to be something that the view should do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top