1
String value = (String) request.getParameter("value"); 

sometimes return null.

How can I fix this?

I am passing the value like this from page to page.

<a href=page2.jsp?value =<%=value %>"> Page2</a>
kitokid
  • 3,009
  • 17
  • 65
  • 101

1 Answers1

1

You shouldn't have any white space before the = sign in your URL, and you should have a quote before the URL:

<a href="page2.jsp?value=<%=value %>">Page2</a>
        ^               ^

You should also encode the parameter value, and avoid scriptlets. Use The JSTL:

<c:url var="page2Url" value="page2.jsp">
    <c:param name="value" value="${someBean.value}"/>
</c:url>
<a href="${fn:escapeXml(page2Url)}">Page2</a>

Read How to avoid Java code in JSP files?

Other than that, any user may remove the parameter from the URL in its address bar, so maybe that's the reason for a null parameter.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255