[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: servlet forward: things happen twice



Thank you for all the helpful inputs. However, they
didn't solve the problem. I am sorry for the mistakes
I made during my cut and paste including this non-stop
recursive call (fortunately, it is never get called
because I am doing a get)...thanks

--- Tim Collins <timmyc8m@yahoo.com> wrote:
> could it be....
> 
> Servlet A
> > > =========
> > > 	public void doPost(HttpServletRequest request,
> > > HttpServletResponse response) throws
> > ServletException
> > > 	{
> > > 		doPost(request, response);
> > > 	}
> 
> you are calling doPost(req,res) inside your doPost.
> 
> Good Luck,
> Tim
> 
> 
> 
> --- kingram@bellsouth.net wrote:
> > > 				RequestDispatcher rd =
> > > getServletContext().getRequestDispatcher("B");
> > > 				rd.forward(request, response);
> >   ^^^^^^^^^^^^^^^^^^
> > > 			} else {
> > > 				RequestDispatcher rd =
> > > request.getRequestDispatcher("C");
> > 
> > I am sure someone out there has the time to
> explain
> > this. (busy at work).  But to me, it seems kind of
> > ambigious on the part of the API to have a
> > getRequestionDispatcher() for
> > javax.servlet.ServletContext and
> > javax.servlet.http.HttpServletRequest.  Does
> someone
> > have a good example where this can be VERY useful?
> > 
> > 
> > 
> > > 
> > > From: Yong Wang <wymz@yahoo.com>
> > > Date: 2003/02/11 Tue AM 11:47:16 EST
> > > To: ajug-members@ajug.org
> > > Subject: servlet forward: things happen twice
> > > 
> > > Hi, I wonder if anyone could spot the problem
> here
> > bcz
> > > I am sure it is something very simple that I
> > > overlooked:
> > > 
> > > I have three servlets, A, B and C, where A
> > forwards to
> > > B or C based on some flags in request parameter.
> > But
> > > when A forwards to B, somehow both servlet A and
> B
> > get
> > > called twice by only a single get request. The
> > > environment is tomcat 4.1.
> > > 
> > > Servlet A
> > > =========
> > > 	public void doPost(HttpServletRequest request,
> > > HttpServletResponse response) throws
> > ServletException
> > > 	{
> > > 		doPost(request, response);
> > > 	}
> > > 
> > > 	public void doGet(HttpServletRequest request,
> > > HttpServletResponse response) throws
> > ServletException
> > > 	{
> > > 
> > > 		String key = (String)
> > request.getParameter("key");
> > > 		String idx = (String)
> > request.getParameter("index");
> > > 
> > > 		try
> > > 		{
> > > 			if (key != null && idx != null) {
> > > 				RequestDispatcher rd =
> > > getServletContext().getRequestDispatcher("B");
> > > 				rd.forward(request, response);
> > > 			} else {
> > > 				RequestDispatcher rd =
> > > request.getRequestDispatcher("C");
> > > 				rd.forward(request, response);
> > > 		} catch (Exception e) {
> > > 			;
> > > 		}
> > > 
> > > Servlet B
> > > =========
> > > 
> > > 	public void doPost(HttpServletRequest request,
> > > HttpServletResponse response) throws
> > ServletException
> > > 	{
> > > 		doPost(request, response);
> > > 	}
> > > 
> > > 	public void doGet(HttpServletRequest request,
> > > HttpServletResponse response) throws
> > ServletException
> > > 	{
> > > 		String key = (String)
> > request.getParameter("key");
> > > 		String idx = (String)
> > request.getParameter("key");
> > > 
> > > 	// do some processing and output to response...
> > > 	}
> > > 
> > > Servlet C (actually a JSP)
> > > ===========
> > > code omitted.
> > > 
> > > I would appreciate any insight. pls email me
> > directly
> > > if you want to see the entire source listing.
> > Thanks!
> > > 
> > > yong
> > > 
> > > =====
> > > 
> > > // My alternate email: yongwang@mindspring.com
> > > 
> > > 
> > >
> __________________________________________________
> > > Do you Yahoo!?
> > > Yahoo! Shopping - Send Flowers for Valentine's
> Day
> > > http://shopping.yahoo.com
> > > 
> > > 
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine's Day
> http://shopping.yahoo.com


=====


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com