• 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

problem setting custom header in response

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having problem setting custom header in my response.I have tried using setHeader(),addHeader()...but i dont see the header in the response.Read some where that we can override setheader() in our response wrapper class.Can some one please tell me how to do that.

thanks in advance
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
show us the code & the response headers.
 
Rahul Birdie
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my servlet :
public void doGet(HttpServletRequest request, HttpServletResponse response){
response.addHeader("name", "rahul");
response.setHeader("name", "rahul");
response.sendRedirect("/some.jsp");}


in my JSP :
<%
Enumeration e =request.getHeaderNames();
while(e.hasMoreElements()){
String header= String.valueOf(e.nextElement());
out.println("Header :" + e.nextElement()+ "<BR>");
out.println("Value : " + request.getHeader(header));
}%>


I am using livehttp header too to check the header.Output from live http


GET /StatusReturn/StatusFilterCode/WebContent/WEB-INF/jsp/final.jsp HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-securid
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: JSESSIONID=54411B48ED5F49AD57DE911CD31A839A

HTTP/1.x 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=4BCAE7B35828BE3426D0EAA075AE4B0C; Path=/
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 273
Date: Wed, 31 Oct 2007 23:35:24 GMT
[ October 31, 2007: Message edited by: Rahul Birdie ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're doing a sendRedirect, you're asking the browser to make another request (to the JSP). Once the browser makes that request, the response header of the previous request are lost.

And in any case, request headers and response headers are different, so the code wouldn't work no matter what.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would a RequestDispatcher & Request Attribute achieve what you are after:

 
Rahul Birdie
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried requestdispatcher too,doesnt seem to set the header....i dont see it in live http header..

GET /StatusReturn/StatusFilterCode/WebContent/WEB-INF/jsp/final.jsp HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-securid
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: JSESSIONID=E92B4D52912EB982974DD7D1F7AE4FCB

HTTP/1.x 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=45DF1E1A2F08BBD1C421CAD57788EC9B; Path=/
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 383
Date: Thu, 01 Nov 2007 01:10:10 GMT
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's back up a bit.
Why are you trying to set a custom header?
There might be a better way to achieve your goal than by using headers.
 
Rahul Birdie
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to create a test env. for which i need to set an error status say 403...but i am not able to do it...i have tried setstatus(403) and the setHeader(SC_ , message) but i am not getting the status in the jsp.I am using only one jsp page.


Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you were to look at the interface for HttpServletResponse you will find the supported means to set an error code.
 
Rahul Birdie
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have looked at the interface but setheader,addheader,setstatus,senderror are the methods i can use and i have tried all of them.I have used filters too but still nothin.In DD i even have specified <error> tags.I still cant figure out what to do.....
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A response code is not a header.
It's part of the start-line.
See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
for more information on HTTP messages.

Did you try using:
response.sendError(response.SC_FORBIDDEN, YOUR_MESSAGE_HERE);
?
 
reply
    Bookmark Topic Watch Topic
  • New Topic