struts如何重定向到同一页面
我对struts比较陌生。 我已经为 login.jsp
和 profile.jsp
编写了代码,两者都包含在同一目录中。 当我成功登录时显示 profile.jap 页面,但当失败时,它不会重定向到同一页面意味着 login.jsp
。
一般登录页面路径是
但是当我失败时它重定向到
我的 struts-config.xml 是
<action input="/login.jsp" name="LoginForm" path="/login" scope="session" type="brandzter.strutsaction.LoginAction">
<forward name="success" path="/jsppages/profile.jsp" />
<forward name="failure" path="/jsppages/login.jsp" />
</action>
我我不明白为什么每当我给出“/jsppages/login.jsp”失败路径时它都会重定向到 login.do 页面。
这是 Action 类 -
public class LoginAction extends org.apache.struts.action.Action {
private final static String SUCCESS = "success";
private final static String FAILURE = "failure";
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LoginForm loginForm = (LoginForm) form;
boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getLoginid(), loginForm.getPassword());
if (availableStatus) {
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
}
}
}
我确实调试了这将转到 login.jsp 页面,但不显示给定的 url。
I am fresher in struts.
I have written code for login.jsp
and profile.jsp
both are contained in same directory.
When I successfully login is showing profile.jap page but when fail its not redirecting to same page means login.jsp
.
generally login page path is
but when I fail its redirecting to
my struts-config.xml is
<action input="/login.jsp" name="LoginForm" path="/login" scope="session" type="brandzter.strutsaction.LoginAction">
<forward name="success" path="/jsppages/profile.jsp" />
<forward name="failure" path="/jsppages/login.jsp" />
</action>
I am not following why its redirecting to login.do page whenever I have given "/jsppages/login.jsp" path for failure.
here is the Action class-
public class LoginAction extends org.apache.struts.action.Action {
private final static String SUCCESS = "success";
private final static String FAILURE = "failure";
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LoginForm loginForm = (LoginForm) form;
boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getLoginid(), loginForm.getPassword());
if (availableStatus) {
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
}
}
}
I did debug this is going to login.jsp page but not showing given url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的错误就在于此。它不会让你通过调用直接获得价值。
登录表单.getLoginid();
你必须这样称呼它
I think your mistake is in this. it will not allowed you to get directly value by calling.
loginform.getLoginid();
You have to called it like this
不太清楚,除非发布您操作中的一些代码。但很可能您正在进行的验证(在
LoginForm
中)失败了。结果,流程被重定向到从根 (/login.jsp
) 配置的action
的已配置input
参数。尝试更改/jsppages/login.jsp
。Not very clear unless to post some code from you action. But most likely you are doing a validation (in
LoginForm
) which is failing. As a result of which the flow is getting redirected to configuredinput
parameter ofaction
which is configured from root (/login.jsp
). Try changing that/jsppages/login.jsp
.