cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a header variable in jsp

Former Member
0 Kudos

Hi ,

I am using Headervariable login module(which takes user id form http header variable) for single sign on.

I configured the login module stack. But to test i need a jsp from which i can pass the user id in http header.

to test if i am able to set the user id in http header , i have written 2 jsps

1. Header.jsp

In this , i am setting the user id

response.addHeader("UserId" ,"user1");

and i am posting it to HeaderResult.jsp

2.HeaderResult.jsp

In this, i am tryng to rretrieve it By using

request.getHeader("UserId");

But i am not geeting any value.

Can i set user defined header variables?if not, can i set the standard http header variabes,

Please help me with the code.

Thanks,

Lakshmi

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Lakshmi,

I have the same problem what u have. Did u solve that Set and Get Header Problem?If so, can u send me the idea of how to solve to my mail id:

sanvani111@rediffmail.com

Thanks,

Sangeetha

guru_subramanianb
Active Contributor
0 Kudos

Hi Lashmi,

or simply put the userid as a hidden variable in the java or servlet like this ,

<input type=hidden value="usrid">

and in the jsp file just get this value back using request.getparameter();

<% request.getParameter(<ur textboxname here >);

Why r u sending userid as a header from one jsp to other?I dont understand this.

hope it helps.

rdgs,

Guru

guru_subramanianb
Active Contributor
0 Kudos

Hi Lakshmi,

Did you have getter & setter methods in your DAO java class.If not write a simple java class which exposes these methods.Once you set the methods you can get the value from these methods.

Also did you try request.getParameter where you hv set in the jsp.

Regards,

Guru

Former Member
0 Kudos

HI Guru,

I have not written any DAO class, since these jsps are only to test if i can pass a userid in header varible.

does the request.getparameter get the http header variables too?

Thanks,

Lakshmi

Former Member
0 Kudos

Hello Lakshmi,

Is there any special reason so that you want to send the userId as a header? When you invoke the response.addHeader() you modify the headers of the response, which are different from the headers of the request. If you want to modify the request you can use filters. Why don't you try to send the user ID as a cookie instead of a header?

Kind Regards

Vyara

Former Member
0 Kudos

Hi Vyara,

You are right,when i add response.addHeader() , it is getting added in the response header. I wanted that in te Request Header. becacuse the header variable login whih i am requesing , will take the Userid fro the Request header. yes i tried setting in the cookie. i see the variable Userid in request, can it be accessed by normal variable? or while retreiving , do we have to retreive it from the cookie.

can ypou send me some code how to change request header using fileters?

Thanks,

Lakshmi.