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!

Setting and Getting Header from Servlet to JSP

Status
Not open for further replies.

DB2Problem

Programmer
Oct 17, 2002
53
US
I have a very typical and conceptual problem. I want a precise answer and I request everyone to

provide me the answer to the best of their understanding. The problem seems simple but it's not

working.

Question Summary -

I am trying to set headers from my Servlet and forwarding to the JSP page. On the JSP page I am

trying to get back the header that was set from the servelt. I get a null

I am using WSAD 5.1 for this testing

Example

// FROM servlet

resp.setHeader("name", "america");

// somewhere down the servlet, I forward to jsp

ServletContext context = getServletContext();
RequestDispatcher requestdispatcher=context.getRequestDispatcher("america.jsp");
requestdispatcher.include(req,resp);

// this is my jsp

String america = request.getHeader("name");

// I am getting null for this line below

System.out.println("america is ="+america);


Note: I have used all premutations/combinations, by getting dispatcher from request (instead of context), using include

instead of forward etc etc.. nothing worked. The header is not returing any value just null

Please advise with concrete solution

Thanks a lot
 
I want a precise answer and I request everyone to

provide me the answer to the best of their understanding.

What the hell does that mean ? Not making any friends here making comments like that.

Anyway, it seems to me you are not using header properties for what they are supposed to be used for - meta data. Things like content type, content length, connection instructions, server types etc. There is no header called 'name' that I know of - you should be using request parameters in my opinion.

Is that ***precise*** enough for you ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
No Sir that's not even close and that's the reason I wrote for a precise answer in the first place. I guess people use this message board for some serious issue they may not find PRECISELY from textbooks.

Think, why the API gives you the method to setHeader from response object and then get from request. There MUST be a reason to it (and don't tell me to contact guys who wrote J2EE API).

 
Well I still think you are using header properties completely incorrectly - and I feel you are incorrectly understanding how headers work.

When you alter a response header object, you are modifying it for the client. So, if I set a header called "qqq", the client will see that header - but the JSP you are forwarding/including to will not see that header, because you still have the same header from the original client.

You can prove this by using wget or some client that can show you header information.

BTW, If I were you , I would drop the attitude with your postings - its not polite, nor funny.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I appologize if my previous comments have offended you or anyone in any ways. That's not my nature or intention in this serious discussion borad. Please except my appology and execuse me if being impolite.

You are absolutely correct and that's how I understood the problem. But the issue is that I am trying to simulate similar behaviour as returned from Siteminder web agent from the servlet I mentioned before. The aim is to set the header and retrieve in the JSP.

So quoting your line -

" So, if I set a header called "qqq", the client will see that header - but the JSP you are forwarding/including to will not"

Who is the client in this case. Do you want to say use sendredirect?? or forward to html..Didn't get this part and if not then how to make it or simulate the similar behaviour

Much appreciated - Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top