重定向通常通过设置动作转发属性redirect="true" 来完成。在您的情况下,您需要创建操作
public class RedirectAction extends ForwardAction {
@Override
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Create a RequestDispatcher the corresponding resource
String path = mapping.getParameter();
if (path == null) {
throw new ServletException(messages.getMessage("forward.path"));
}
// Let the controller handle the request
ActionForward retVal = new ActionForward(path, true);
retVal.setContextRelative(true);
return retVal;
}
}
或者自然使用配置
<action path="/ProtectedPageAction" type="org.yourname.struts.actions.ProtectedPageAction"
parameter="ProtectedPage" roles="admin">
<forward name="success" path="/Homepage.do" redirect="true"/>
</action>
public class ProtectedPageAction extends Action {
@Override
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Let the controller handle the request
ActionForward retVal = mapping.findForward("success");
retVal.setContextRelative(true);
return retVal;
}
}