简体   繁体   English

如何在Struts中重定向到同一页面

[英]How to redirect to same page in struts

I am fresher in struts. 我在支柱方面更新鲜。 I have written code for login.jsp and profile.jsp both are contained in same directory. 我已经为login.jspprofile.jsp编写了代码,它们都包含在同一目录中。 When I successfully login is showing profile.jap page but when fail its not redirecting to same page means login.jsp . 当我成功登录时,显示的是profile.jap页面,但失败时,不重定向到同一页面意味着login.jsp

generally login page path is 通常登录页面路径是

http://localhost:8000/brand/jsppages/login.jsp HTTP://本地主机:8000 /品牌/ jsppages / login.jsp的

but when I fail its redirecting to 但是当我无法重定向到

http://localhost:8000/brand/login.do HTTP://本地主机:8000 /品牌/ login.do

my struts-config.xml is 我的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>

I am not following why its redirecting to login.do page whenever I have given "/jsppages/login.jsp" path for failure. 我没有遵循为什么每当我给出失败的“ /jsppages/login.jsp”路径时为什么将其重定向到login.do页面。

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. 我确实调试了这将进入login.jsp页面,但未显示给定的URL。

boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getLoginid(), loginForm.getPassword());

I think your mistake is in this. 我认为您的错误在于此。 it will not allowed you to get directly value by calling. 它不会允许您通过致电直接获得价值。 loginform.getLoginid(); loginform.getLoginid(); You have to called it like this 你必须这样称呼它

boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getString("PropertyNameofTextBox"), loginForm.getString("PropertyNameofTextBox"));

Not very clear unless to post some code from you action. 除非您从操作中发布一些代码,否则不是很清楚。 But most likely you are doing a validation (in LoginForm ) which is failing. 但是最有可能的是您正在验证失败(在LoginForm )。 As a result of which the flow is getting redirected to configured input parameter of action which is configured from root ( /login.jsp ). 结果,流被重定向到从根( /login.jsp )配置的action已配置input参数。 Try changing that /jsppages/login.jsp . 尝试更改该/jsppages/login.jsp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM