struts如何重定向到同一页面

发布于 2024-12-07 23:29:54 字数 1686 浏览 0 评论 0原文

我对struts比较陌生。 我已经为 login.jspprofile.jsp 编写了代码,两者都包含在同一目录中。 当我成功登录时显示 profile.jap 页面,但当失败时,它不会重定向到同一页面意味着 login.jsp

一般登录页面路径是

http://localhost:8000/brand/jsppages/login.jsp< /p>

但是当我失败时它重定向到

http://localhost:8000/brand/login.do

我的 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

http://localhost:8000/brand/jsppages/login.jsp

but when I fail its redirecting to

http://localhost:8000/brand/login.do

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫罗兰の梦幻 2024-12-14 23:29:54
boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getLoginid(), loginForm.getPassword());

我认为你的错误就在于此。它不会让你通过调用直接获得价值。
登录表单.getLoginid();
你必须这样称呼它

boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getString("PropertyNameofTextBox"), loginForm.getString("PropertyNameofTextBox"));
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();
You have to called it like this

boolean availableStatus = CustomerManager.matchUserIdPassword(loginForm.getString("PropertyNameofTextBox"), loginForm.getString("PropertyNameofTextBox"));
心不设防 2024-12-14 23:29:54

不太清楚,除非发布您操作中的一些代码。但很可能您正在进行的验证(在 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 configured input parameter of action which is configured from root (/login.jsp). Try changing that /jsppages/login.jsp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文