Hi All,
I would like to know which is the best approach for session tracking in
struts among the following
1) Writing your own ActionServlet class which will have the
following code
public class MyActionServlet extends ActionServlet{
/* (non-Javadoc)
* @see
org.apache.struts.action.ActionServlet#doGet(javax.servlet.http.HttpServ
letRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
System.out.println(" Inside doGet Method of
MyActionServlet");
String id = request.getRequestedSessionId();
System.out.println(" The REQUEST SESSION ID IS
::"+id);
HttpSession session=request.getSession(true);
System.out.println(" Value of the new SESSION
OBJECT IS :;"+session.getId());
System.out.println(" Is it a new session object
? :;"+session.isNew());
if (!(id.matches(session.getId())))
{
System.out.println("************************************");
System.out.println("*********SESSION TIME
OUT********");
System.out.println("************************************");
}
super.doGet(request,response);
}
2) Writing a base action and checking for session expiry in
that class
public class DisplayProfileAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
{
HttpSession session= HttpSession
session=request.getSession(true);
Boolean valid=session.getParameter("VALID");
if (valid == null)
{
System.out.println("************************************");
System.out.println("*********SESSION TIME
OUT********");
System.out.println("************************************");
}
}
}
3) Or using the following code. Any suggestion as to where should
this code be placed. In your own action servlet class or in BaseAction
class
if (!request.isRequestedSessionIdValid())
{
System.out.println("************************************");
System.out.println("*********SESSION TIME OUT ********");
System.out.println("************************************");
}
4) Using filters (Cookies) to track session timeout which by using
filters will the performance of the system not get affected?
Thanks & Regards
Prerna
The information contained in this electronic message and any attachments to
this message are intended for the exclusive use of the addressee(s) and may
contain proprietary, confidential or privileged information. If you are not the
intended recipient, you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately and destroy all copies of this message and
any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should
check this email and any attachments for the presence of viruses. The company
accepts no liability for any damage caused by any virus transmitted by this
email.
www.wipro.com