• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet - doGet - doPost - parameter

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a jsp page (test.jsp), two servlets (Servlet1 and Servlet2).
In test.jsp, parameters are submitted using a form and test.jsp calls Servlet1's doPost method.
Then, in Servlet1, I use response.sendRedirect("/Servlet2") or getServletContext.getRequestDispatcher("/Servlet2") to call the second servlet.
My problems are: (1) Servlet1 always called the doGet method of Servlet2, I want Servlet1 to call the doPost method of Servlet2. (2) The parameters sent from test.jsp are not passed from Servlet1 to Servlet2.
Can someone help?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,
doGet() method is called by default when the form's method attribute is not explicitly set. You must use requestdispatcher.forward("/servlet")to call the next servlet in chain. Then the doPost() method will be invoked and request parameters will be available to the servlet.
Regards,
[ March 25, 2003: Message edited by: Lakshmi Dasari ]
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to Lakshmi:
I viewed j2ee api doc,but I cannt find you have posted method,"requestdispather.forward("/servlet")"
In apis,requestdispather's method as follows:
public void forward(ServletRequest request,
ServletResponse response)
throws ServletException,
java.io.IOException
would u like explain for me?
 
Lakshmi Dasari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi wang ,
U r right. That was a syntax error. It should be as follows:
getServletContext().getRequestDispatcher("/NextServlet").forward(request,response);
Thanks for the correction
Regards,
 
There's a city wid manhunt for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic