sendRedirect() to a servlet?

Is it possible for a servlet to use the sendRedirect() method to redirect a request to another servlet, preserving the parameter information?  I have been able to use this method to redirect a request to a static html page, but when I try to redirect to a servlet, I get error messages.

If this is not possible, what is the easiest way to have a servlet send form information to another servlet?


Who is Participating?
Ravindra76Connect With a Mentor Commented:
Hi skylar1,

You Can.

1.But parameters to be passed in querystring.

No posted parameters.

You compulsory has to extend HttpServlet

Assume that your HttpServletResponse is res.


2.Another way of interservlet communication is


will return a servlet.

Call the necessary methods.

Note: Before redirecting, you won't write any data in the current servlet
by getting stream or writer from curretn servlet res object.

Best of lcuk.
you need something like this

 (req, res);

11) How do you pass data (including beans) to a JSP from a servlet?
TOC There are actually three different ways to do it, depending on how long the reference should last, and which JSP pages (and servlets, for that matter) should be able to see it. In each of the cases, assume that "myBean" is a reference to the bean you want to send, and that "theBean" is the key I'm going to use to store the bean under (from the servlet perspective), and use as the identity of the bean in the JSP page.
These techniques are portable to any environment compliant with the servlet API 2.1 and JSP 1.0 specifications. In each case, the passing
works from servlet->JSP, servlet->servlet, JSP->JSP, or JSP->servlet transitions.
(1) Request Lifetime
Use this technique to pass beans that are relevant to this particular request to a bean you are calling through a request dispatcher (using either "include" or "forward"). This bean will disappear after processing this request has been completed.
    request.setAttribute("theBean", myBean);
    RequestDispatcher rd =
    rd.forward(request, response);
    <jsp:useBean id="theBean" scope="request" class="....." />
(2) Session Lifetime
Use this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it.
    HttpSession session = request.getSession(true);
    session.putValue("theBean", myBean);
    /* You can do a request dispatcher here,
        or just let the bean be visible on the
        next request */
    <jsp:useBean id="theBean" scope="session" class="..." />
(3) Application Lifetime
Use this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it.
    getServletContext().setAttribute("theBean", myBean);
    <jsp:useBean id="theBean" scope="application" class="..." />
All Courses

From novice to tech pro — start learning today.