A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
EJB 3 in Action
this week in the
EJB and other Java EE Technologies
Cookies and Struts
Joined: Nov 23, 2004
Feb 28, 2005 07:00:00
My application starts of with an index.jsp page where the user inputs his name and email address, this call an action 'createCookie' where the details are stored in a cookie.
I need the details to be read from the cookie and displayed to the user the next time he opens the webpage.
The relevant code int index.jsp
<logic :-P resent cookie="cename"> <bean:cookie id="namecookie" name="cename"/> <bean:write name="namecookie" property="name"/> <bean:write name="namecookie" property="value"/> <html:text property="ename" size="50" maxlength="50" [B][I]value="<bean:write name="namecookie" property="value"/>"[/I][/B]/> </logic :-P resent>
The revelant code in createCookie.java
Cookie nameCookie = new Cookie("cename", briefingInfoForm.getEname()); nameCookie.setMaxAge(10000); Cookie emailCookie = new Cookie("ceemail", briefingInfoForm.getEemail()); emailCookie.setMaxAge(10000); response.addCookie(nameCookie); response.addCookie(emailCookie);
The code in bold italics in index.jsp in the text input box is where I am getting the error. If any one could point me the right way to do this, it will be great.
The error I get is "attribute nameCookie has no value", even though the line above that prints out the value of the nameCookie.
Thanks a bunch
[ February 28, 2005: Message edited by: Achal Jalan ]
Joined: Feb 15, 2005
Feb 28, 2005 16:15:00
Code, simply remove the "value" attribute. In a Struts <html:text> tag, the value comes from the property attribute, and the value attribute generally does not need to be specified.
Joined: Dec 17, 2002
Jun 18, 2007 19:34:00
In the above scenario, if we want to display the cookie value in a text-box (instead of read-only label), how do we display the same?
The below code doesnt display it in the text-box, even though until the previous line, the cookie value is coming... can someone point out my mistake?
<html:text name="logonForm" property="username" size="16" value='<bean:write name="unameCookie" property="value"/>' />
I think Merrill said something about
...the value comes from the property attribute..
Does that mean the cookie name & the text-box name must be same??
My jsp code is -
<logic :-P resent cookie="edm.unameCookie"> <bean:cookie id="unameCookie" name="edm.unameCookie"/> <bean:write name="unameCookie" property="value"/> <html:text name="logonForm" property="username" size="16" value='<bean:write name="unameCookie" property="value"/>' /> </logic :-P resent> <logic:notPresent cookie="edm.unameCookie"> <html:text name="logonForm" property="username" value="" size="16"/> </logic:notPresent>
I agree. Here's the link:
subject: Cookies and Struts
Iterate Hashmap of object
No getter method for property username of bean User
struts -- Cannot find bean under name indexedWorkInProgressVO
When to use logic:present tag
cookies in struts
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014