I am using Struts2 for my project.
Working on simple registration project. When user Login , he is directed to his profile, but on hitting browser’s back button login page appears again.
XML:
<action name="home" class="bharat.Home">
<result name="success">/jsp/home.jsp</result>
<result name="student">/jsp/Welcome.jsp</result>
</action>
<action name="Login" class="bharat.LoginAction">
<result name="input">/index.jsp</result>
<result name="success">/jsp/Welcome.jsp</result>
</action>
Home.java:
public String execute() {
if((String)ActionContext.getContext().getSession().get("studentName")!=null)
{
return "student";
}
if((String) ActionContext.getContext().getSession().get("instructorName")!=null)
{
return "instructor";
}
session = ActionContext.getContext().getSession();
session.put("roleName","notAdmin");
return SUCCESS;
}
Home.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="cache-control" content="no-cache" />
<meta name="expires" content="0" />
<meta name="pragma" content="no-cache" />
<sx:head/>
I want that when user hit back button after being logged in , he must be redirected back to same page. Can anyone Help me please..
You can use post and redirect method where all you need to when user login he/she should be redirected to welcome page.
If you see banking sites or any other secure site they have deployed the same mechanism and it work perfectly fine.
Secondly i suggest not to play with
ActionContextas Struts2 has given you a more clean and flexible way to implementSessionAwareinterface, by implementing this your Action is free from underlying framework dependencies and easy to test