Struts 2 Troubleshooting
How to add session in struts2 action class:
You can access the session object using a jsp scriplet and set your required
variables there.
<%
request.getSession().setAttribute("your_variable",obj)
%>
From the Action class , you can get access to session either by implementing
the ServletRequestAware
Interface within your action class or by implementing the SessionAware
interface.
request.getSession().getAttribute("var");
variables there.
<%
request.getSession().setAttribute("your_variable",obj)
%>
From the Action class , you can get access to session either by implementing
the ServletRequestAware
Interface within your action class or by implementing the SessionAware
interface.
request.getSession().getAttribute("var");
ref:
OR
add an attribute "private Map session;" in Action class. create getters and setters. use below code to put and get values from sesiion.
session = ActionContext.getContext().getSession();
session.put("logged_in", "no");
boolean loggedIn = (Boolean) session.get("logged-in");
session.remove("selectedMatch");
Comments
Post a Comment