• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

jsp:forward doubt

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
sanla palati
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
even i am thinking same. but dont have any idea why the answere 3 i right
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jsp 2.0 spec. 6.2.2.

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

Thanks or your clarification.

Thanks,
Sanla
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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)
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John, I would have never thought 3 would be right answer, If I wouldn't had seen this post.

Vijay Bheemineni.
 
reply
    Bookmark Topic Watch Topic
  • New Topic