• 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

Response header

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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

Raghunath
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raghunath Nandyala
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Raghunath Nandyala
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic