Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting info about request object.

Status
Not open for further replies.

lovekang

Programmer
Feb 16, 2006
86
KR
I want all the infomation about request object not only headers and mayby body or contents.
the page below don't show anything. what's the problem?

Thanks in advance.

<%@ page import = "java.io.*" %>
<%@ page import = "javax.servlet.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%
ServletInputStream is = request.getInputStream();
StringBuffer sb = new StringBuffer();
byte[] b = new byte[1024];
for (int n; (n = is.read(b)) != -1;) {
sb.append(new String(b, 0, n));
}
%>
<%=sb%>
</body>
</html>
 
Hi

It works for me. And I think the reason it does not work for you is not Java related, but pure HTTP/1.1

To have anything available on the input, you have to POST something to it. I mean, request it through a [tt]form[/tt] with [tt]method[/tt] attribute set to [tt]post[/tt].

By the way, your question is more appropriate to forum695.

Feherke.
 
all I can see are parameters and their values.
 
Hi

In your code you output the data received on the standard input. The data available on the standard input is the data received through POST. And yes, that is the form data, that is the body of the request. What do you want more ?

Feherke.
 
I've thought
request.getInputStream() gives the request hearder and body.
for example port, host name etc and of course the parameters and values.
yes you can get the information about headers by using other APIS like request.getHeaders...

you mean request.getInputStream() gives only the parameters and their values only if the request method is "post". right?
 
API says about getInputStream() is like this.
Retrieves the body of the request as binary data using a ServletInputStream.
then request is composed of headers and body.
and body is composed of parameters and their values.
and headers can be viewed with getHeaders(java.lang.String name)
and body can be viewed with getInputStream().
right?
tell me more about request objects structure.
Thanks in advance.
 
Hi

Yes. That is how all CGI and similar environments, including servlet containers, work.

I am not the right person to tell you more about them. I am able to help on small bugs, but better I do not explain. ( As I wrote, previous explanation was HTTP/CGI, not Java. )

You can find the experts in forum695, I suggest to ask there.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top