Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Referer page

 
Roger Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a small html and a JSP page. The jsp page is trying to find out if the referer page is
numLimit.html.
HTML page (numLimit.html)
<html>
<head>
</head>
<body>
<form method="GET" action="test.jsp" name="form1">
<input type="submit" value="Submit" name="sButton">
<input type="hidden" name="previousPage" value="9">
</form>
</body>
</html>
============
JSP page (test.jsp)
<html>
<head></head>
<body>
<% if (request.getParameter("previousPage"
== "9")%>
got it!!!
<% else %>
nope!
</body>
</html>
However, the JSP page always prints out "nope" even though I am expecting "got it!"
Do anybody know why?
Thanks.
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi roger,
problem is not with html,problem is with your jsp code.
/**************just make following changes in jsp ****/ or cut it from here and paste it your jsp and try.
/********CODE STARTS************/
<html>
<head></head>
<body>
<%
String test = request.getParameter("previousPage");

if(test.equalsIgnoreCase("9"))
{
%>
got it!!!
<%
}
else
{
%>
nope!
<%
}
%>
</body>
</html>
/**************CODE ENDS HER**************/
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use compareTo() to compare Strings:
<% if ( (request.getParameter("previousPage")).compareTo("9")==0 %> got it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic