Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to link two servlets?

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to link two servlets?

    i am new to servlets and learning; i have a doubt regd. servlets;

    below is servlet1

    pub. class servlet1 extends Http...{
    public void doGet(...)...{
    out.println(...");
    // i am using form's post method from here and the values of this form should be accessed in servlet2
    out.println("<form method='post' action='servlet2'>");
    out.println("message: <input type='text' name='message'>");
    out.println("subject: <input type='text' name='subject'>");
    out.println("</form>");
    }
    }

    below is the servlet2

    pub. class servlet2 extends Http...{
    public void doGet(...)...{
    MYQUESTION: now i want to get the details (values of input text's like message, subject of servlet1's form) here (in servlet2) whatever i entered in the
    servlet1's form;

    }
    }

    plz help me....

    urs madhukar


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: plz help servlets

    Hello bhmadhukar, welcome to the Java Programming Forums

    These 2 links will answer all of your questions!

    Servlet Tutorial: Handling Form Data

    Tim's Servlet Tutorial : Reading Form Data


    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    May 2009
    Location
    Mumbai/ Bombay - India
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: plz help servlets

    I think in the servlet2 you have to use the doPost() method and not the doGet() method.

    One of the parameter of the doPost() method is an object of HttpServletRequest. You use this object's getParameter() method to retrieve your desired values.

    In your case it would be something like:
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws Exception{
     String subject = req.getParameter("subject");
     String message = req.getParameter("message");
     //rest of your code
    }

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: plz help servlets

    hi friends,

    thank you, i solved this program.

    urs madhukar

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: plz help servlets

    Hello bhmadhukar,

    Care to share your solution?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Replies: 1
    Last Post: May 19th, 2009, 09:19 AM