I’m having a servlet in which i want to compare the request parameters. I’m using following code
<body>
<%
if(request.getParameter("type")!=null)
{
if(request.getParameter("type").equals("recover"))
{
%>
<h1>Recover</h1>
<%
}
}
else if(request.getParameter("type")!=null)
{
if(request.getParameter("type").equals("reset"))
{
%>
<h1>Reset</h1>
<%
}
}
%>
</body>
but this jsp gives a compile time exception stacktrace follows
org.apache.jasper.JasperException: An exception occurred processing JSP page /recover.jsp at line 16
</head>
<body>
<%
if(request.getParameter("type").equals("recover")) <--- line16
{
%>
<h1>Recover</h1>
I don’t know whats going wrong because this is the correct way to compare strings.
Why don’t you use the JSTL instead:
You wouldn’t have to care about the parameter being null, and it would be much cleaner. scriptlets should not be used anymore. And that’s true for a loooong time.