---
title: "JSP URL重写"
author: "331855843"
date: "2010-07-09T20:32:01Z"
tags: ["HTML", "JSP", "Struts", "Web", "XML"]
categories: ["编程语言"]
slug: "jsp-url"
draft: false
lastmod: "2010-07-09T20:32:01Z"
id: 709452
url: "https://331855843.iteye.com/blog/709452"
---

首先要去下载一个urlrewritefilter-2.6.zip,然后把它解压到WEB-INF下，然后配置一下web.xml UrlRewriteFilter org.tuckey.web.filters.urlrewrite.UrlRewriteFilter logLevel WARN UrlRewriteFilter /* action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml debug 3 detail 3 0 action \*.do index.jsp 然后再随便建立几个jsp页面，如：MyJsp.jsp &lt;%@ page language="java" pageEncoding="utf-8"%&gt; My JSP 'index.jsp' starting page &lt;% String a = request.getParameter("id"); %&gt; &lt;% if(a.equals("123")) { out.println("ok!"); } else { out.println("okok!"); } %&gt; 接着在urlrewrite.xml里配置一下路径 The rule means that requests to /test/status/ will be redirected to /rewrite-status the url will be rewritten. /test/status/ %{context-path}/rewrite-status /test/(\[0-9]+) /index.jsp?id=$1 The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url) the url /rewrite-status will be rewritten to /test/status/. The above rule and this outbound-rule means that end users should never see the url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks in your pages. /rewrite-status /test/status/ 启动服务器，然后输入http://localhost:8080/test/123 ,那么就可以显示了,而实际上读取的路径是http://localhost:8080/MyJsp.jsp?id=123