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

how to pass parameters between servlet  RSS feed

 
sangamesh magi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,i am trying to pass parameters from html->servlet1->servlet2 and in reverse order like servlet2->servlet1->html, Please anybody can help me!!!



Thanks in advance
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see http://www.coderanch.com/t/363153/Servlets/java/passing-methods-one-servlet-another
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sangamesh magi:
hi,i am trying to pass parameters from html->servlet1->servlet2 and in reverse order like servlet2->servlet1->html, Please anybody can help me!!!



Thanks in advance


from HTML to Servlet - you can pass it as request parmeters using GET pr POST method from HTML and the same can be retrieved in Servlet using <b>request.getParamter("paramName")</b>

From Servlet to Servlet - put the value you want to pass in any of the scopes such as request, session or appliaction.
<b> request.setAttribute("MyAttribute","MyValue") session.setAttribute("MyAttribute","MyValue") application.setAttribute("MyAttribute","MyValue")
</b>

then get the RequestDispatcher of the resource you want to forward to.
In the forwarded resource, you can get the attributes using
<b> request.getAttribute("MyAttribute")
session.getAttribute("MyAttribute") application.getAttribute("MyAttribute")
</b>

Note :
1) Please note that there is a difference between parameters and attributes.
2) While forwarding using RequestDispatcher, the response should not be committed before the forward happens.

Hope this Helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!