• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what should be output

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i am reading data manually of Get Method.
It is printing just:
<br>reader.readLine().
but the o/p is comming in the url and it is just printing:
<br>reader.readLine().
while i think it should also print the second line i.e:
reader.readLine():WHAT EVER I PASS IN POSTSERVLET.
or print with null or should throw exception.
I tried in tomcat4 and tomcat3 in both but out put is same.
What should be the o/p in your opinion.
Here is the code.

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
public class PostServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title></title>");
out.println("</head>");
out.println("<body>");
out.println("<form action=LoginPage method=Get>");
out.println("<input type=text name=name>");
out.println("<input type=text name=rollno>");
out.println("<INPUT TYPE=submit name=confirm>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
}
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;
public class LoginPage extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
{
BufferedReader reader=req.getReader();
System.out.println("<br>reader.readLine()");//1
System.out.println("<br>reader.readLine()"+reader.readLine());//2
}

}
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beats me... .
Although I don't understand the need to do a getReader() on the Request object.
I tried some combinations like adding a doPost() method etc, but doesn't answer your qstn.
- satya
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Data passed can be seperated by emty lines. That is probably the case here. Try changing

to

This will show you everything sent by the browser in the body.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[b]
String lineIn = null while((lineIn = reader.readLine()) != null) { System.out.println("<BR>reader.readLine() : " + lineIn); }[/v]
Nope. Din't do much good either.
Attempted in IE and NS using Tomcat 4.0.1.
regds.
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
knock....knock....knock.....
ersin....Guy....Axel....Ashik....faiza..anybody!!!
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here it is dark outside and friday.
GMT +1
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I got a Timeout-Exception in the log file. Maybe its a question for a jakarta newsgroup, but I am really to tired. Was a hard week.


You should have the same:
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServletResponse getReader will read the information passed to the servlet in the Post InputStream. The information being past here is a GET and Not a post. Change the form to do a post and change the LoginPage to implemtent the doPost method and see your results. (ps, then try my other changes )
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServletResponse getReader...
HttpServletRequest getReader, that is right?
Will try.
- satya
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getReader() returns a BufferedReader which retrives the body of the request as character data.
The difference between GET and POST requests,as we all know, is that in a "GET" form data is encoded into a URL, whereas in a "POST" the form data appears in the message body.
Changing the method to POST should display the expected output. To see the same in GET use request.getQueryString()
I have tested this in WebLogic6.1 and it works fine, after changing to POST.
[ January 25, 2002: Message edited by: Sita Kotamraju ]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree it works with POST. I verified with Tomcat.
So does this confirm that in the initial code with the GET method, nothing gets passed in the message body and so there was nothing to read?
Thanks.
- satya
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It demonstrats some of what you need for Objective:
1.2 For each of the HTTP methods, GET, POST, and HEAD, identify triggers that might cause a browser to use the method, and identify benefits or functionality of the method.
I think Ken's notes had a good discussion of the rest
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOB
I been telling to myself BufferedReader.readLine() reads the body, but never thought about checking the action="Get" ! DuH! I assumed that it was POST
 
Sita Kotamraju
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Madhav Lakkapragada:
I agree it works with POST. I verified with Tomcat.
So does this confirm that in the initial code with the GET method, nothing gets passed in the message body and so there was nothing to read?
Thanks.
- satya


I would like to know that too...however, getContentLength() returns a -1(unknown length) with a GET.
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
new explanation why it don't work with doGet().
Api states retrieves the body of the request as character data using a BufferedReader.
I strongly believe that a http-get request has NO body, whereas a post request has. Can't find it, but I can sweare that I read something about that a http-post has a special body section, where you find all the paramName-paramValue pairs.
Please comment on this.
Axel
 
jawwad ahmed
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i know that this code work with post request.
But the specification does't told about retrieving data from the request object.
As in the above code the data is retrieved on the next page but only appear as query string.it does not print the data on the screen.I think it is bug in tomcat or it is the case of rfc about the http methods.
reply
    Bookmark Topic Watch Topic
  • New Topic