2013-07-27 28 views
0

例如在我允許用戶自己授權的每個頁面上。但在行動LoginAction我每次將他移動到main.jsp,因爲req.getRequestURI返回帶有動作的url localhost:8080/reservation/LoginAction.do從動作重定向到同一頁面

這裏是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"; 

如何獲取引起操作頁面?頁面上

形式如下

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

回答

1

當我使用這個,我已經隱藏在申請表格中,包含實際的URL(或頁面)。登錄用戶後,我使用該值重定向到最後一頁。

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

你讀到它的行爲像這樣'string value = req.getGetparameter(redirect_page)'? – lapots

+1

是的...這就是我使用這種方式 –