Since String
is an object, not a primitive, the ==
would only compare them by reference, not by the object's internal representation. You need to compare them by equals()
instead.
if("page1".equals(request.getParameter("page")))
// do something
else if("page2".equals(request.getParameter("page")))
// do something else
(note, this style is done so to prevent potential NullPointerException
on for example request.getParameter("page").equals("page1")
when the parameter returns null
)
Related questions:
Unrelated to the problem, the JSP is not the best place for this job. Consider a Servlet.