aspose file tools*
The moose likes Servlets and the fly likes Response header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Response header" Watch "Response header" New topic
Author

Response header

Raghunath Nandyala
Ranch Hand

Joined: Jan 24, 2006
Posts: 64
Hi

How to get information inside response(not request) header ?

Raghunath


SCBCD,SCWCD,SCJP
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

I'm going to go down the path of... why would you want to do this? Think of the response as an output file. Why would you want to read a file you were in the middle of writing? You could store this information elsewhere while you were writing the file for use later since its likely to be better managed in memory as a set of complex objects than a single stream.


My Blog: Down Home Country Coding with Scott Selikoff
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
I'll go down the path of ... a slight language barrier.

Putting info into the reponse header:

setHeader
addHeader
setIntHeader

Or, retrieving info from the response header:

getBufferSize
getCharacterEncoding
getContentType
getLocale
[ October 17, 2006: Message edited by: sven studde ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Response header is somthing that is read by the browser (Considering browser as your request maker).If you want to see the headers , then try telenting into the http server and see what the server sends as response.After the frist line of the response and before the body , all are http headers.


Rahul Bhattacharjee
LinkedIn - Blog
Raghunath Nandyala
Ranch Hand

Joined: Jan 24, 2006
Posts: 64
Hi

There is a big story..
Im caching error code by using
<error-page>
<error-code>500</error-code>
<location>/Message.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/Message.jsp</location>
</error-page> .. so on
Now when ever it 500 error comes it will go to Message.jsp, but I neet to log the error code(which is the part of response header) what actually error code that web-app got.And Message.jsp will do loging part..

I can do this by having different pages like Message500.jsp Message400.jsp..

but I want to make it as simple.

Thanks
Raghunath
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
If you are using tomcat (this may be the case for other app servers) the information about the error is available to the JSP.

if you look at the request attibute values you will see something like


javax.servlet.forward.request_uri:
javax.servlet.forward.context_path:
javax.servlet.forward.servlet_path:
javax.servlet.forward.query_string:
javax.servlet.error.servlet_name:
javax.servlet.error.exception:
javax.servlet.error.request_uri:
javax.servlet.jsp.jspException:
javax.servlet.error.status_code: 500

Add this to your error jsp to see the attributes:



also you can get access the exception itself through the "exception" var.

i.e.


Let me know if you need a more detailed example. Also, is it not possible to simply create a seperate JSPs (pages) for the error codes?


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
Raghunath Nandyala
Ranch Hand

Joined: Jan 24, 2006
Posts: 64
Thanks Reshid..

But I want to get header from response(what servlet is going to send to the client) not request.

There is no method in HttpResponse to get information from the header.

Raghunath.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
I suppose, if you really really really want to log response codes that way you could implement a Filter that substitutes your own HttpServletResponseWrapper custom class with one custom method setStatus(sc) that looks at the code before passing it to the enclosed HttpServletResponse.

Bill
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Maybe I am still misunderstanding the question. javax.servlet.error.status_code: <error code> is the value that the server sends to the client. The container is required to set this value.

Remember you are forwarded to this jsp during the error. The attribute does not originate from the client.

Please see Servlet 2.3: New features exposed

Scroll down to the error reporting explaination and example

[ October 18, 2006: Message edited by: Rashid Mayes ]

Sorry about the invalid URL. The URL should be

http://servlets.com/soapbox/servlet23.html
[ October 19, 2006: Message edited by: Rashid Mayes ]
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
Rashid,

Invalid URL.

Raghunath Nandyala,

Go here instead:

http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi.html?page=4

The example on page 4 shows you how do what you want, which is what Rashid was describing. It does seem funny that the error codes are put in the request.
[ October 19, 2006: Message edited by: sven studde ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Response header