简体   繁体   English

从操作重定向到同一页面

[英]redirect from action to the same page

For example on every page I allow user to authorize himself. 例如,在每个页面上,我允许用户授权自己。 But in action LoginAction I move him to main.jsp every time because req.getRequestURI returns url with action in it localhost:8080/reservation/LoginAction.do . 但是在操作LoginAction我都会将其移至main.jsp因为req.getRequestURI返回的URL包含localhost:8080/reservation/LoginAction.do

Here is LoginAction 这是LoginAction

     HttpSession session = req.getSession();

    log.debug("attempt to checkuser");

    String login = req.getParameter("login");
    String password = req.getParameter("password");

    if (loginService.checkExists(login, password)) {
        session.setAttribute("enterAttr", true);
        session.setAttribute("loginame", login);
        return "main";
    }

    session.setAttribute("enterAttr", false);
    return "redirect:/reservation/main.jsp";

How to get page that cause action? 如何获取引起动作的页面?

Form on page looks like this 页面上的表格看起来像这样

<form action="LoginAction.do" method="POST">
            <div id="table"
                class="ui-widget-header ui-corner-all ui-widget-content">
                <table align="center" style="width: 100%">
                    <tr>
                        <td align="center"><span
                            style="color: white; font-size: 20px;"><fmt:message
                                    key="lg" /></span></td>
                        <td align="right"><input type="text" id="login" name="login" />
                        <td>
                    </tr>
                    <tr>
                        <td align="center"><span
                            style="color: white; font-size: 20px;"><fmt:message
                                    key="paswd" /></span></td>
                        <td align="right"><input type="password" id="password"
                            name="password" /></td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2"><input type="submit"
                            id="approve" style="font-size: 10px;"
                            value="<fmt:message key='enter'/>" /></td>
                    </tr>
                </table>
            </div>
        </form>

When I am using this, I have hidden filed in form, that contains actual URL (or page). 使用此功能时,我隐藏了包含实际URL(或页面)的表单文件。 After login user, I use that value to redirect to last page. 登录用户后,我使用该值重定向到最后一页。

<input type="hidden" name="redirect_page" value="some_info" /> 

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

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