By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

logout problem using struts

P: 10
hi everybody.
I have following problem.
There are two pages. index.jsp and main.jsp in my application
Index.jsp contains logging interface in .
It submits password and userid to loginform bean.

following are entries in struts-config.xml file
Expand|Select|Wrap|Line Numbers
  1.   <action input="index.jsp" name="loginform" path="/login" scope="session" type="com.myapp.struts.loginaction">
  2.             <forward name="success" path="/main.jsp"/>
  3.         </action>
  4.  
  5.         <action  path="/logout" scope="session" type="com.myapp.struts.logoutaction">
  6.             <forward name="logout" path="/index.jsp"/>
  7.     </action>
  8.  
on successfully logged in control is forwarded to main.jsp file. On main.jsp file their is one image having logout caption . so code for it is as follows
Expand|Select|Wrap|Line Numbers
  1. <html:link page="/logout.do"> <img src="img/logout_deselect.jpg" name="Image11"  height="30" border="0"> </html:link> 
  2.  
Now actionforms are as follows
loginaction.java
Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * loginaction.java
  3.  *
  4.  * Created on February 26, 2007, 10:48 AM
  5.  */
  6.  
  7. package com.myapp.struts;
  8.  
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. import org.apache.struts.action.Action;
  13. import org.apache.struts.action.ActionForm;
  14. import org.apache.struts.action.ActionMapping;
  15. import org.apache.struts.action.ActionForward;
  16. /**
  17.  *
  18.  * @author root
  19.  * @version
  20.  */
  21.  
  22. public class loginaction extends Action {
  23.         /**
  24.      * This is the action called from the Struts framework.
  25.      * @param mapping The ActionMapping used to select this instance.
  26.      * @param form The optional ActionForm bean for this request.
  27.      * @param request The HTTP Request we are processing.
  28.      * @param response The HTTP Response we are processing.
  29.      * @throws java.lang.Exception
  30.      * @return
  31.      */
  32.     public ActionForward execute(ActionMapping mapping, ActionForm  form,
  33.             HttpServletRequest request, HttpServletResponse response)
  34.             throws Exception {
  35.  
  36.         loginform lform=(com.myapp.struts.loginform) form;
  37.      //   String uid="Welcome" + lform.getUserid()+"";
  38.        // request.getSession().setAttribute("userName",uid);
  39.         response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
  40. response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
  41. response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
  42. response.setHeader("Pragma","no-cache");
  43.  
  44.         request.getSession();
  45.         request.getSession().setAttribute("loginform",lform);
  46.         return mapping.findForward("success");
  47.     }
  48. }
  49.  
logoutaction.java is as follows
Expand|Select|Wrap|Line Numbers
  1.  /*
  2.  * loginaction.java
  3.  *
  4.  * Created on February 26, 2007, 10:48 AM
  5.  */
  6.  
  7. package com.myapp.struts;
  8.  
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. import org.apache.struts.action.Action;
  13. import org.apache.struts.action.ActionForm;
  14. import org.apache.struts.action.ActionMapping;
  15. import org.apache.struts.action.ActionForward;
  16. /**
  17.  *
  18.  * @author root
  19.  * @version
  20.  */
  21.  
  22. public class logoutaction extends Action {
  23.  
  24.     /* forward name="success" path="" */
  25.  //   private final static String SUCCESS = "success";
  26.  
  27.     /**
  28.      * This is the action called from the Struts framework.
  29.      * @param mapping The ActionMapping used to select this instance.
  30.      * @param form The optional ActionForm bean for this request.
  31.      * @param request The HTTP Request we are processing.
  32.      * @param response The HTTP Response we are processing.
  33.      * @throws java.lang.Exception
  34.      * @return
  35.      */
  36.     public ActionForward execute(ActionMapping mapping, ActionForm  form,
  37.             HttpServletRequest request, HttpServletResponse response)
  38.             throws Exception 
  39.     {
  40.       // request.getSession().setAttribute("userName",null);
  41.        request.getSession().removeAttribute("loginform");
  42.        request.getSession().invalidate();
  43.        return mapping.findForward("logout");
  44.  
  45.     }
  46. }
  47.  


So when i clicks on logout image the control is forwarded to index.jsp
But when i press backbutton of the browser the main.jsp page is displayed.
i.e. logout is not working properly.
I want functionality like when back button will be pressed "session expirred messaged should be displayed and control should be forwared to index.jsp page

Can anybody help me out with this
Sep 3 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Javascript and Java are not the same language. Moved to the Java forum.
Sep 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.