Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Forward request to servlets using RequestDispatcher  RSS feed

 
Kalidha kani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to forward a request using "RequestDispatcher". I have JSP pageContext object. I tried to forward my request to my servlet "MyServlet" using the following code. I set some attributes in my request and forwarded it. But i am not able to access those variables in my servlet class.

My code :
pageContext.getRequest().setAttribute("AValue","A");
pageContext.getRequest().setAttribute("BValue", "B");

RequestDispatcher rd = pageContext.getRequest().getRequestDispatcher("/MyServlet");
rd.forward(pageContext.getRequest(),pageContext.getResponse());

Help me. Thanks in advance.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth would you be forwarding a request from a JSP to a servlet? And does this mean that you are putting Java code in your JSPs?

Back up a bit and tell us what you are really trying to accomplish because it sounds like you are heading off in the wrong direction.

P.S. Servlets have no concept of a page context; that is a JSP-only concept.
 
Kalidha kani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I am doing this in one of my server codes.
From my custom tag library class i got the pagecontext object.Based on some condition I am forwarding it to corresponding servlets. My problem is in my servlet calss I am not able to access the values I set. wat am i doin wrong?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very usual to forward from a custom tag to a another resource. After all you are in the middle of processing a JSP, why would you abruptly need to go somewhere else? Again, please tell us what you are actually trying to accomplish -- not how you are trying to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!