aspose file tools*
The moose likes JSP and the fly likes EL cookie Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "EL cookie Problem" Watch "EL cookie Problem" New topic
Author

EL cookie Problem

Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
hi all,

I am getting this as output

Cookie name is :javax.servlet.http.Cookie@17509be








Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Ankitt,

try ${cookie.username.value}

Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Balu Sadhasivam wrote:
Ankitt,

try ${cookie.username.value}




Yes Balu,i tried but when i am running the code it is displaying blank but after refreshing the page it displays the correct result.
And please can you explain why "value" is needed
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The ${cookie.username.value} basically does like getCookieByName("username").getValue(). The cookie class at its own has several getter method like getValue(), also see javax.servlet.http.Cookie.

I should add, although this is clearly a test case, but in real life you shouldn't use a cookie for this kind of information. Rather use the HttpSession.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Bauke Scholtz wrote:The Cookie class doesn't have a getUsername() method at all. How did you come into it?
Read the API doc which getters are all available: javax.servlet.http.Cookie.

I should add, although this is clearly a test case, but in real life you shouldn't use a cookie for this kind of information. Rather use the HttpSession.



But i am taking the value from
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

Ankitt Gupta wrote:can you explain why "value" is needed

Your original EL expression reference the cookie instance. To obtain its value, you need to reference the value property. This is the same as for any other bean instance.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Ankitt Gupta wrote:

But i am taking the value from

Sorry, I misinterpreted the problem, I've edited my reply.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Bear Bibeault wrote:
Ankitt Gupta wrote:can you explain why "value" is needed

Your original EL expression reference the cookie instance. To obtain its value, you need to reference the value property. This is the same as for any other bean instance.


ok i got it ...it was basically printing the objects toString()

but the correct result is displayed after refreshing..On running for the first time it displays a blank
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Ankitt Gupta wrote:
Balu Sadhasivam wrote:
Ankitt,

try ${cookie.username.value}




Yes Balu,i tried but when i am running the code it is displaying blank but after refreshing the page it displays the correct result.
And please can you explain why "value" is needed



Here "username" is just a cookie name , and uses "value" property to fetch the value ( internally uses getValue() of Cookie Class.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

Ankitt Gupta wrote:but the correct result is displayed after refreshing..On running for the first time it displays a blank

Cookies are a good way to remember data on the client for later, but are not a great way to transfer data to the client.

Remember, cookies are a client-side mechanism. When you "create" a cookie on the response you are actually doing no such thing. You are creating a header on the response that tells the browser to create the cookie when it gets the response.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Indeed, hence my HttpSession suggestion.

Only use a cookie if you really know/understand what you're actually doing. Do not choose solutions randomly.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
Much Appreciated Thanks to Everyone.

I don't know whether it is appropriate to ask here but still....can anyone provide me some article or notes on paths i.e context-path,class path etc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL cookie Problem