Java Reference
In-Depth Information
That way, we can send them to that page after a successful login. To
do that, we just need to add a hidden parameter for loginUrl in the login
form:
Download email_34/web/WEB-INF/jsp/login.jsp
<s:form beanclass="stripesbook.action.LoginActionBean">
<%-- ... --%>
<s:hidden name="loginUrl"/>
</s:form>
Finally, we add a loginUrl property in LoginActionBean and use it after a
successful login. If the user went straight to the Login page, there is no
loginUrl , and we send the user to the Message List page in that case.
Download email_34/src/stripesbook/action/LoginActionBean.java
public Resolution login() {
getContext().setUser(user);
if (loginUrl != null ) {
return new RedirectResolution(loginUrl);
}
return new RedirectResolution(MessageListActionBean. class );
}
public String loginUrl;
Logged-in users have to be able to log out, too. It's simple to imple-
ment a LogoutActionBean that delegates the session-handling details to
MyActionBeanContext :
Download email_34/src/stripesbook/action/LogoutActionBean.java
package stripesbook.action;
public class LogoutActionBean extends BaseActionBean {
public Resolution logout() {
getContext().logout();
return new RedirectResolution(LoginActionBean. class );
}
}
Download email_34/src/stripesbook/ext/MyActionBeanContext.java
public void logout() {
setUser( null );
HttpSession session = getRequest().getSession();
if (session != null ) {
session.invalidate();
}
}
The user is removed from the action bean context, and the session is
invalidated.
 
Search WWH ::




Custom Search