J2EE實現登入後自動跳轉到登入前訪問的頁面

來源:互聯網
上載者:User

 

擷取當前訪問URI並儲存於session中:

String uri = request.getRequestURI();String param = "";try {if(request.getQueryString() != null) {param = new String(request.getQueryString().getBytes("ISO8859-1"),"UTF-8");}} catch (UnsupportedEncodingException e) {e.printStackTrace();}if(!param.equals("")) {uri += "?"+param;}session.put("uri", uri);

當登入失敗時跳轉到失敗頁面,當登入成功時跳轉到當前訪問的頁面或者給予提示:

下面是struts2跳轉提示頁面代碼

<%@page contentType="text/html;charset=utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>跳轉提示</title><script type="text/javascript" src="/js/jquery-1.4.min.js"></script><script type="text/javascript">var second=3;$(function() {$("#secondSpan").text(second+"");var fuc = function(){second-=1;$("#secondSpan").text(second+"");if(second==0) {location="${uri}";}else{setTimeout(fuc,1000);}};fuc();//開始倒計時});</script></head><body><div><h2>${curUser.username }您已成功登陸!</h2><h3>   </h3><h3>頁面在<span id="secondSpan"></span>秒後將重新轉回 <a href="${uri}"></a>。如果轉入失敗,請單擊<a href="${uri}">這裡</a>。</h3> </div></body></html>

在登入處理的servlet或者action中不要做記錄,否則可能陷入迴圈。。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.