File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet - doGet - doPost - parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet - doGet - doPost - parameter" Watch "Servlet - doGet - doPost - parameter" New topic

Servlet - doGet - doPost - parameter

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
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?

Thanks,<br />Mike
Lakshmi Dasari
Ranch Hand

Joined: Mar 03, 2003
Posts: 35
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.
[ March 25, 2003: Message edited by: Lakshmi Dasari ]

qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
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,
would u like explain for me?

Thanks...qingwu<br />When I open my eyes,I see your pretty face.
Lakshmi Dasari
Ranch Hand

Joined: Mar 03, 2003
Posts: 35
hi wang ,
U r right. That was a syntax error. It should be as follows:
Thanks for the correction
I agree. Here's the link:
subject: Servlet - doGet - doPost - parameter
It's not a secret anymore!