I took the following code example from a Struts2 textbook, the purpose of the code is to set a cookie in the Action class, then the jsp page is supposed to take out the content from the cookie and then display.
LoginAction class:
public class LoginAction implements Action,ServletResponseAware{
private HttpServletResponse response;
...
public void setServletResponse(HttpServletResponse response)
{
this.response=response;
}
public String execute() throws Exception
{
Cookie c= new Cookie("user",getUsername());
c.setMaxAge(60*60);
response.addCookie(c);
return SUCCESS;
}
JSP page:
<html>
<head>
<title>Cookie Success Page</title>
</head>
<body>
<br/>Welcome ${cookie.user.value}, thanks for logging in.
</body>
</html>
The issue I am having now is that the ${cookie.user.value} will always be shown as blank, no matter what username I have supplied.
Maybe this is not a good way of setting cookie values in Struts2?
cookieis just aMapbehind the scenes. To access a Map interface from EL use${cookie["user"].value}