servlet input contnet

O

odelya

Hi!
I am trying to extract content from ServletInputStream:

ServletInputStream cont = request.getInputStream();
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(cont));
sb.append(br.read());
System.out.println(sb.toString());
System.out.println(request.getContentLength());

But i get:
-1
-1
Why can't it read it?
 
O

odelya

Hi!
I am trying to extract content from ServletInputStream:

ServletInputStream cont = request.getInputStream();
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(cont));
sb.append(br.read());
System.out.println(sb.toString());
System.out.println(request.getContentLength());

But i get:
-1
-1
Why can't it read it?


I would like to add:
what im trying to do, is to get the content when the user clicks on a
link to open the page (not by submitting it)
 
O

ohaya

odelya said:
I would like to add:
what im trying to do, is to get the content when the user clicks on a
link to open the page (not by submitting it)


Hi,

I think that when they click on a link, which sends an HTTP GET request
to the webserver, there is no "content". When they do a submit, which
sends an HTTP POST (e.g., submitting a form), then there is "content"
which can be read.

Jim
 
L

Lothar Kimmeringer

ohaya said:
I think that when they click on a link, which sends an HTTP GET request
to the webserver, there is no "content". When they do a submit, which
sends an HTTP POST (e.g., submitting a form), then there is "content"
which can be read.

Nearly ;-) There is only content that can be read, if there
is content being sent. If there is content, will be estimated
with the content-type. With a Content-type of
application/x-www-form-urlencoded (that will be sent if a
form is submitted using POST) I wouldn't expect data that can
be read from the stream, either. The data will be already read
by the surrounding ServletContext to enable use
request.getParameter(...)

But I might be wrong and you should just try it.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top