This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:forward  doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:forward  doubt" Watch "jsp:forward  doubt" New topic
Author

jsp:forward doubt

sanla palati
Ranch Hand

Joined: Oct 17, 2007
Posts: 36
Hi,

I got this question.

---------------------------------------------------------------

Assume that in your JSP page, you need to forward the request to another page. The url to this page is given by a request parameter named 'redirectto'.

Which of the following code snippets do the above task?



1.<jsp:forward page="request.getParameter('redirectto')" />

2.<% request.getRequestDispatcher( request.getParameter("redirectto") ).forward(request, response); %>

3.<jsp:forward page="%=request.getParameter('redirectto')%" />

4.<jsp:forward page="<%=request.getParameter('redirectto')%>" />

5.<jsp:forward page="%request.getParameter('redirectto')%" />

i thought 2& 3 would be correct answeres. But 2,3,&4 are right. Any comments ? please

Thanks,
Sanla
Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
I can see why 2 & 4 are correct. In 4 you are getting the value of a parameter and then you use it in jsp:forward, the expression <%= %> will print the value of our parameter.

now I can't get 3
%=request.getParameter('redirectto')% doesn't look like a valid expression, where are the < & >, shouldn't we use them here (like number 4)?


SCBCD - SCWCD - SCJD - SCJP - OCA
sanla palati
Ranch Hand

Joined: Oct 17, 2007
Posts: 36
even i am thinking same. but dont have any idea why the answere 3 i right
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
jsp 2.0 spec. 6.2.2.

Gurukant Desai
Ranch Hand

Joined: Apr 07, 2008
Posts: 56
John, So you mean to say that only option 3 "<jsp:forward page="%=request.getParameter('redirectto')%" />
)" is right and option 4 "<jsp:forward page="<%=request.getParameter('redirectto')%>" />" is wrong?
Because I think both 3 and 4 are right..
Please clarify...
sanla palati
Ranch Hand

Joined: Oct 17, 2007
Posts: 36
Hi John,

Thanks or your clarification.

Thanks,
Sanla
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332

Because I think both 3 and 4 are right..

Both should be right,.. but 3 should be OK only in JSP documents (JSP with XML syntax)
Vijay Bharghav bheemineni
Greenhorn

Joined: Aug 31, 2005
Posts: 29
Thanks John, I would have never thought 3 would be right answer, If I wouldn't had seen this post.

Vijay Bheemineni.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:forward doubt
 
Similar Threads
request object in multiple jsp pages
Pop up new HTML page in JSP
jsp:forward
"%=request.getParameter('redirectto')%" is this the correct syntex??
JSP Forward