Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem while forwording the JSP page

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is the code for A.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>JSP Example For SCJD</title>
</head>
<body>
<%! String who="";%>
<form>
Enter your name:<input type="text" name="who">
<input type=submit value="Submit">
</form>
<jsp:forward page="welcome.jsp">
<jsp aram name="who" value="<%= who%>"/>
</jsp:forward>
</body>
</html>
and below is the code for welcome.jsp
<html>
<head>
<title>Trupti's first JSP for SCJD</title>
</head>
<body>
<%--<%! String name="";%>--%>
Welcome!! <%=who%>.
This is my first example for the SCJD study group.
</body>
</html>
when I submit the name, the welcome.jsp should display the line with the name entered by the user.
e.g. welcome!! trupti
But the A.jsp directly forwords the request to welcome.jsp without showing the form.
How do I achieve it?
thanks,
Trupti
[ November 27, 2002: Message edited by: trupti nigam ]
[ November 27, 2002: Message edited by: trupti nigam ]
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Trupti,
i guess what u want is,
simple HTML that has a form having Name field and Submit button and then the action for that form to be "welcome.jsp".
when u click on Submit after entering the Name it should go to Welcome page that says "Welcome, <<user>>", right?
if i were u , i would have done following,
<html>
<form name='f' action='/jsp/Welcome.jsp' method=post>
<input type='text' name='name' value='Trupti'>
<input type='submit' name='submit' value='Submit'>
</form>
</html>
and Welcome.jsp code is fine.
regards,
Maulin
 
franci
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the jsp:forward tag takes to the specified page without any delay, so the code will not work. The solution given by maulin is perfectly ok. it will work
 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Trupti,
There is small change in welcome.jsp.You are passing the parameter to welcome.jsp thru jsp param but in welcome.jsp you should get the same param by using the getParameter("<parameter name>") into the string and then print it in the scriptlet.Hope it helps you.
Ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic