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 4 of 4

Thread: servlet response

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question servlet response

    Hi,

    this is my server code:
    	protected void doPost(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
                    boolean res = false;
    		...
    		PrintWriter writer = response.getWriter();
    		writer.println(res);
    		writer.close();
    	}
    this is a client site:
    ...
    			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    ...
    			BufferedReader reader = new BufferedReader(
    					new InputStreamReader(connection.getInputStream()) );
    ...
    How can I get a res from server?

    I can get "200 OK" (e.g. connection.getContent() etc.), I can get html (with reader), but I don't found, how can I get the res from writer.println(res).

    Thanks in advance.
    -booj


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: servlet response

    What the PrintWriter wrote in your servlet should be what is read with your reader on the client side. What content does the client side read? Are you sending data to the servlet via an HTTP POST request (if not, you should use the doGet method)?

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: servlet response

    yes, via POST
    			connection.setRequestMethod( "POST" );
    			connection.setDoInput( true );
    			connection.setDoOutput( true );
    			connection.setUseCaches( false );
    			connection.setRequestProperty( "Content-Type",
    			"application/x-www-form-urlencoded" );
    			connection.setRequestProperty( "Content-Length", String.valueOf(body.length()) );
    			OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() );
    			writer.write( body );
    			writer.flush();

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: servlet response

    > What content does the client side read?
    HTML Site

Similar Threads

  1. Replies: 0
    Last Post: March 11th, 2012, 04:57 PM
  2. httpServlet response
    By lorik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 17th, 2011, 10:29 AM
  3. collecting information/moving from servlet to servlet
    By CBird in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 1st, 2011, 06:04 PM
  4. Replies: 6
    Last Post: April 14th, 2009, 08:02 AM