2個(gè)Web應(yīng)用集成問(wèn)題解決
2臺(tái)機(jī)器部署了2個(gè)Web應(yīng)用,A應(yīng)用需要訪(fǎng)問(wèn)B應(yīng)用的URL。為了保證URL不會(huì)讓任意用戶(hù)隨便粘貼就可以訪(fǎng)問(wèn),需要在B應(yīng)用上加上filter攔截請(qǐng)求,并進(jìn)行權(quán)限校驗(yàn)。A應(yīng)用的URL給用戶(hù)看來(lái)是一個(gè)中間跳轉(zhuǎn)頁(yè)面的URL。在這個(gè)中間頁(yè)面,添加hidden的value,在B應(yīng)用的filter端進(jìn)行value的校驗(yàn)。代碼如下:
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('不允許訪(fǎng)問(wèn)');
- <%
- }
- %>
- }
- </script>
- </head>
- <body onload="init()">
- <form method="post" id="myForm">
- <input type="hidden" name="key" id="key" value="MERKTLTTOR">
- </form>
- </body>
- </html>
這是filter頁(yè)面,實(shí)際中可以是真正的過(guò)濾器filter。
中間頁(yè)面采用post提交,用戶(hù)在url中看不到提交的hidden。
中間頁(yè)面的form的action可以用request.getParamter()獲取
當(dāng)然value可以采用一些加密算法進(jìn)行加密。
原文鏈接:http://liwenjie.javaeye.com/blog/919015
【編輯推薦】