send request body while invoke servlet

Posted on 2011-10-28
Last Modified: 2012-05-12
I want invoke a servlet which will read the request body of the request call. Basically, I need to make a request to this servlet and send a string in the request body, the servlet on receiving will read the string. How do I acheive this?
Question by:greenearth
    LVL 86

    Expert Comment


    Author Comment

    I will try to work with this sample and see how far i got to this..
    LVL 27

    Accepted Solution

    Here is an example. First, a test JSP.
    <form action="read" method="post">
    <input type="text" name="message" value="test"/>
    <input type="submit" />

    Open in new window

    package rrz;
    import javax.servlet.*;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class ReadBodyServlet extends HttpServlet {
        public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            BufferedReader reader = request.getReader();
            String line;
            while((line = reader.readLine()) != null){

    Open in new window

    LVL 27

    Expert Comment


    Open in new window


    Author Closing Comment

    Yes this make sense. I was making myself over complicated
    LVL 86

    Expert Comment

    >>the servlet on receiving will read the string

    The accepted answer is not doing that though ...

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    EvenOdd challenge 10 68
    linearIn  challenge 23 54
    instanceof  operator in java 26 56
    Logs to delete in Windows VCenter server ? 11 92
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now