This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Referer page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Referer page" Watch "Referer page" New topic
Author

Referer page

Roger Chan
Ranch Hand

Joined: Nov 13, 2001
Posts: 30
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

Joined: Nov 22, 2001
Posts: 393
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**************/


Regards,
James
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
You can also use compareTo() to compare Strings:
<% if ( (request.getParameter("previousPage")).compareTo("9")==0 %> got it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Referer page
 
Similar Threads
error in Textbox
Simple jsp:useBean question
is there anything like formpost in jsp?
request Attribute doubt?
Another simple question