HttpServletResponse sending Parameter to a JSP?

Discussion in 'Java' started by Duke, May 6, 2008.

  1. Duke

    Duke Guest

    public class Portal extends HttpServlet{
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    {
    response.setContentType("text/html");
    String name="Duke";
    response.sendRedirect("show.jsp");
    }
    }

    in the abow servlet Howto send the name variable as the parameter to
    the show.jsp
    Thank
    DUKE
    Duke, May 6, 2008
    #1
    1. Advertising

  2. Duke

    Arne Vajhøj Guest

    Duke wrote:
    > public class Portal extends HttpServlet{
    > public void doGet(HttpServletRequest request,
    > HttpServletResponse response)
    > throws IOException, ServletException
    > {
    > response.setContentType("text/html");
    > String name="Duke";
    > response.sendRedirect("show.jsp");
    > }
    > }
    >
    > in the abow servlet Howto send the name variable as the parameter to
    > the show.jsp


    For redirect you will need to put in the URL.

    If you used forward then you could have just stored in in
    the request object.

    Arne
    Arne Vajhøj, May 6, 2008
    #2
    1. Advertising

  3. Duke

    Arne Vajhøj Guest

    Arne Vajhøj wrote:
    > Duke wrote:
    >> public class Portal extends HttpServlet{
    >> public void doGet(HttpServletRequest request,
    >> HttpServletResponse response)
    >> throws IOException, ServletException
    >> {
    >> response.setContentType("text/html");
    >> String name="Duke";
    >> response.sendRedirect("show.jsp");
    >> }
    >> }
    >>
    >> in the abow servlet Howto send the name variable as the parameter to
    >> the show.jsp

    >
    > For redirect you will need to put in the URL.
    >
    > If you used forward then you could have just stored in in
    > the request object.


    BTW, if your app supports login you should use response.encodeURL !

    Arne
    Arne Vajhøj, May 6, 2008
    #3
  4. Duke

    Duke Guest

    How to Send the parameter in case of forward?
    Duke
    Duke, May 6, 2008
    #4
  5. Duke

    Arne Vajhøj Guest

    Duke wrote:
    > How to Send the parameter in case of forward?


    request.setAttribute("name", "Duke");

    before doing the forwards.

    Arne
    Arne Vajhøj, May 6, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Landis

    HttpServletResponse.sendError

    Mike Landis, Aug 8, 2003, in forum: Java
    Replies:
    1
    Views:
    4,368
    Dave Miller
    Aug 9, 2003
  2. Joerg Mueller-Tolk
    Replies:
    2
    Views:
    1,008
    Joerg Mueller-Tolk
    Dec 3, 2003
  3. Naresh Agarwal
    Replies:
    0
    Views:
    422
    Naresh Agarwal
    May 28, 2004
  4. Naresh Agarwal
    Replies:
    1
    Views:
    1,052
    ExGuardianReader
    May 29, 2004
  5. Tim
    Replies:
    0
    Views:
    631
Loading...

Share This Page