jsp URL 재 작성

6968 단어 urlrewrite
다음은 사용 설명:
1. url rewrite 다운로드, 공식 다운로드 주소: http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip
2. 압축 파일 을 풀 고 압축 파일 을 프로젝트 에 복사 합 니 다 (압축 파일 위치 - > 프로젝트 위치).
urlrewrite-2.6.0-src/webapp/WEB-INF/lib/urlrewrite-2.6.0.jar -> WebRoot/WEB-INF/lib/urlrewrite-2.6.0.jar
url rewrite - 2.6.0 - src / webapp / WEB - INF / url rewrite. xml - > WebRoot / WEB - INF / url rewrite. xml 3. 웹. xml 에 다음 코드 를 추가 합 니 다.
<filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>
            org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 4. url rewrite. xml 수정
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
        "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">

<!--

    Configuration file for UrlRewriteFilter
    http://tuckey.org/urlrewrite/

-->
<urlrewrite>
	<!--      -->
    <rule>
        <from>^/way1</from>
        <to >/notParam.jsp</to>
    </rule>
    
    <!--       -->
    <rule>
        <from>^/way2([0-9]+)$</from>
        <to >/onlyParam.jsp?id=$1</to>
    </rule>
    
    <!--       -->
    <rule>
        <from>^/way3([0-9]+)/([a-z]+)/([0-9a-zA-Z]+)$</from>
        <to >/manyParam.jsp\?id=$1&amp;name1=$2&amp;name2=$3</to>
    </rule>
</urlrewrite>


 
 
5. index. jsp 만 들 기
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!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">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>URL   </title>
	 <script type="text/javascript">
		function formSubmit()
		{

			var way=document.getElementById("way").value;
			if(way==1){
				form1.action="way1"
				form1.submit();
			}
			if(way==2){
				form1.action="way2"+way
				form1.submit();
			}
			if(way==3){
				form1.action="way3"+way+"/admin"+"/admin110"
				form1.submit();
			}
		}
	</script>
  </head>
  
  <body>
  <form name="form1" id="form1"  method="post">
  	<h1>URL   </h1>
  	<select name="way" id="way">
  		<option value="1">     URL</option>
  		<option value="2">    URL(    )</option>
  		<option value="3">    URL(    )</option>
  	</select>
  	<input type="button" value="  " onclick="formSubmit()"/> 
  </form>
  </body>
</html>

  
메모: 여기 action 은 way 1 을 제출 합 니 다.
6. notParam. jsp 만 들 기
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!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">
<html>
  <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>   </title>
  </head>
  
  <body>
       
  </body>
</html>

 7. onlyParam. jsp 만 들 기
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!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">
<html>
  <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>   -  </title>
  </head>
  
  <body>
    id:<%=request.getParameter("id") %>
  </body>
</html>

 8. manyParam. jsp 구축
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!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">
<html>
  <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>   -  </title>
  </head>
  
  <body>
  	<h2>  :<%=request.getParameter("id") %></h2>
    <h2>  :<%=request.getParameter("name1") %></h2>
    <h2>     :<%=request.getParameter("name2") %></h2>
  </body>
</html>

  
 

좋은 웹페이지 즐겨찾기