Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem displaying implicit request attributes on the forwarded page.

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

I wrote the following servlet code:



This is the forwarded JSP:


I am trying to print the 5 implicit attributes available to the forwarded JSP. Its printing the following 3 attributes:
javax.servlet.forward.request_uri

javax.servlet.forward.context_path

javax.servlet.forward.servlet_path

I am not getting the java.servlet.forward.query_string attribute displayed on the JSP.
But if i did a request.getQueryString(). It is displaying the query string properly in the JSP. Is there anything i missed out?

Kindly provide me a solution.

Thanks,
Vijay






 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The meaning of the "javax.servlet.forward.query_string" is different from what you're expecting it to be. With getQueryString(), you'll get the request parameters passed to the JSP. "javax.servlet.forward.query_string" will contain the parameters passed to the calling servlet, not those passed to the JSP. Try to call "http://localhost:8080/servlets/RequestHeaders?hi=1". You'll see that in this case the "javax.servlet.forward.query_string" is set.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Christopher,

Thank you very much for the reply.

One more doubt:

The JSP is translated to a servlet. So, shouldn't it display the javax.servlet.forward.query_string?

Thanks,
Vijay
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP is translated to a servlet. So, shouldn't it display the javax.servlet.forward.query_string?

The problem is not about being a JSP or a servlet. The problem is about which query parameters you want to get.

For example, A forwards to B. In B, if you want to retrieve the parameters passed to A, you'll use "javax.servlet.forward.query_string". If you want to retreive the parameters passed to B, you'll call getQueryString.

In your example, RequestHeaders is A, and Hello.jsp is B. If you don't pass any paramaters to RequestHeaders, "javax.servlet.forward.query_string" will not be set.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now, i understood the concept.

Thank you very much Chris, for the explanation.


Regards,
Vijay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic