jsp - How to work with cookies in Struts 2 -
i using cookie avoid havind sid (session id). try set cookie using following method , retrieve in jsp file shown blew, not work. shows hellosessionid.
java
public class users { public void setcookie(){ cookie user = new cookie("user","miro"); user.setmaxage(60*60); }
jsp
<%@ page language="java"%> <% cookie cookies[] = request.getcookies(); (int i=0; i<cookies.length; i++) { out.println("hello"+cookies[i].getname()+ "> "); } %>
you need define path cookies. example make accessible in pages of application use following
user.setpath("/"); or user.setdomain("example.com");
Comments
Post a Comment