Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookie access with EL expression

 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sudipto shekhar
Ranch Hand
Posts: 823
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please edit your post and put your code using UBB code.

Thank you.
 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic