wood burning stoves 2.0*
The moose likes JSP and the fly likes Cookie access with EL expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Cookie access with EL expression" Watch "Cookie access with EL expression" New topic
Author

Cookie access with EL expression

Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

I want to access a cookie by a JSP with EL expression however I can't get the value part.. Here my servlet code that creates a cookie;





And the code extract from JSP


Cookie easy access :

- Not working




I can get the cookie with the code below however I need to learn how to access only EL expression thank you for your answers...


//cookie reader code
Cookie[] cookies = request.getKookies(); // changed intentionaly to getKookies() (C->K) because there is a hacker control for specific method!!! java ranch ruless.
for(Cookie c : cookies)
{
if(c.getName().equals("username"))
{
String username = c.getValue();

response.getWriter().print("welcome " + username);
break;
}
}
[ December 12, 2008: Message edited by: Anut Walidera ]

blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Hey I tried out your code and it's working fine.
The name is displayed in the next jsp page.

Can you show your code to us so that we can understand it?
What is the error message that you are getting?

Thank you.


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

Cookie easy access :


code:
--------------------------------------------------------------------------------

${cookie.username.value }

--------------------------------------------------------------------------------

- Not working


Did you tried with this code!! I tried again it is not working....
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Yes my dear I tried out the same.

Why don't you post your code along with the error message!
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

There is no error message, nothing is printed...

below is my servlet and JSP code...



I call my servlet with another jsp page


and I have seen kookie created!!! in the output


Then I call my jsp page.....
below is jsp code


IMPORTANT NOTE: I changed all 'c' ' with 'k' because JAVARANCH security policies requires it!!!

[ December 12, 2008: Message edited by: Anut Walidera ]

[ December 12, 2008: Message edited by: Anut Walidera ]



EDITED :thumb:
[ December 12, 2008: Message edited by: Anut Walidera ]
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Please edit your post and put your code using UBB code.

Thank you.
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

I have edited!! and I am really confused It should be worked!I think nothing seems wrong but I can't see the Value of the cookie!!!

I only see on the jsp

Cookie easy access :

but value prints nothing!!!



[ December 12, 2008: Message edited by: Anut Walidera ]
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Originally posted by Anut Walidera:
There is no error message, nothing is printed...

below is my servlet and JSP code...



I call my servlet with another jsp page











Make sure you type the C and c very carefully.

I got the name in my jsp whit the same code you posted.

I repeat "Make sure you type the C and c very carefully."
[ December 12, 2008: Message edited by: Sudipto Shekhar ]
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

No it is not the problem I just changed C to K while I posting code to forum , normally there isn't any K in my code...
Yes you are right I tried in different machine, It works...

But I do not know Why it didn't work in the other machine...


This is not the reason.... There should be other thing but what ?




[ December 12, 2008: Message edited by: Anut Walidera ]
[ December 12, 2008: Message edited by: Anut Walidera ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie access with EL expression