2個Web應用集成問題解決
2臺機器部署了2個Web應用,A應用需要訪問B應用的URL。為了保證URL不會讓任意用戶隨便粘貼就可以訪問,需要在B應用上加上filter攔截請求,并進行權限校驗。A應用的URL給用戶看來是一個中間跳轉頁面的URL。在這個中間頁面,添加hidden的value,在B應用的filter端進行value的校驗。代碼如下:
Html代碼
- <%@ page language="java" contentType="text/html;
- charset=UTF-8"
- pageEncoding="UTF-8"%>
- <html>
- <head>
- <title></title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <script type="text/javascript">
- function init(){
- document.getElementById('myForm').action="http://localhost:8080/ext2.2/Filter.jsp"
- document.getElementById('myForm').submit();
- }
- </script>
- </head>
- <body onload="init()">
- <form method="post" id="myForm">
- <input type="hidden" name="key" id="key" value="MERKTLTTOR">
- </form>
- </body>
- </html>
Html代碼
- <%@ page language="java" contentType="text/html;
- charset=UTF-8"
- pageEncoding="UTF-8"%>
- <html>
- <head>
- <title></title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <script type="text/javascript">
- function init (){
- <%
- String key=request.getParameter("key");
- if(!"MERKTLTTOR".equals(key)){
- %>
- alert('不允許訪問');
- <%
- }
- %>
- }
- </script>
- </head>
- <body onload="init()">
- <form method="post" id="myForm">
- <input type="hidden" name="key" id="key" value="MERKTLTTOR">
- </form>
- </body>
- </html>
這是filter頁面,實際中可以是真正的過濾器filter。
中間頁面采用post提交,用戶在url中看不到提交的hidden。
中間頁面的form的action可以用request.getParamter()獲取
當然value可以采用一些加密算法進行加密。
原文鏈接:http://liwenjie.javaeye.com/blog/919015
【編輯推薦】