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:
<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.
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
:
package
stripesbook.action;
public class
LogoutActionBean
extends
BaseActionBean {
public
Resolution logout() {
getContext().logout();
return new
RedirectResolution(LoginActionBean.
class
);
}
}
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