doGet/doPost issue

I have 2 servlets and i want to pass the request object(user input) of servletA to the request object of servletB. In other words just pass the request object from one servlet to another. So my code would look something like this.

class ServletAextends HttpServlet{

publicvoid doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

ServletB servletB =new servletB();

//Would servletA request & response objects be now accessible in ServletB?

servletB.doGET(request, response);

}

}

Something tells me that this is a lousy way of doing things but I need the request object in ServletB for processing. Is this approach ok? If not any suggestions?

[1099 byte] By [Robbie_Ca] at [2007-10-2 19:40:14]
# 1
not ok at all. this is not how servlets work. they run in a container.the right way to do it is to forward or redirect the request from servlet A to servlet B.%
duffymoa at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi,

i will show u with an example.

class servlet1 extends HttpServlet

{

public void doGet(HttpServletRequest req,HttpServletResponse res)

{

RequestDispatcher rd=req.getRequestDispatcher("/second");

rd.forward(req,res);

}

}

In the above example,/second is the URL-Pattern of second servlet

class

i hope u understand what i have written.

regards

strictly_helpfula at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Cheers men. I am using that approach now. But I do still have another problem. Put simply how do you combine 2 request object's. If servlet_B's request object already holds information then there is no space to allow the forwarding of info from Servlet_A to Servlet_B. Anyone any suggestions. I am stuck on this problem for quite some time now.

Robbie_Ca at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hi,

Assume that are two clients X and Y . X is requesting SERVLET A and

Y is requesting SERVLET B. From SERVLET A the request is forwarded to SERVLET B. So, now there are two requests to SERVLET

B. As java supports multithreading, two threads are created one for

Client X request and one for Client Y . For each thread, there will be a service method running parallely . So, multiple requests are handled at a time.

So, combining doesn't take place

i hope u understand what i have written.

regards,

strictly_helpfula at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Yes I do but my problem is still not solved. How does Servlet_B know from where the request object was sent from i.e. from client x or y?
Robbie_Ca at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

I suppose the problem can be better explained like this. You have n number of servlets and each servlet has n number of clients so you end up with n number of request objects. In the nth servlet (i.e. the last servlet to be called) you want all those servlets represented in the nth servlets request object. In otherwords it holds all the information from the other servlets. This is very convenient because now you have one large object representing all the others instead of having related information scattered all over the place. But can this be achieved?

Robbie_Ca at 2007-7-13 22:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...