使用urlrewritefilter-4.0.3.jar
配置web.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> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
在web.xml同级目录新建urlrewrite.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"> <urlrewrite> <!-- 新闻中心开始 --> <rule> <from>^/web/news/newsCenter.html$</from> <to type="forward">/web/news/newsCenter.do</to> </rule> <!-- 新闻中心结束 --> <!-- 新闻详细页开始 --> <rule> <from>^/web/news/newsParticular/n_id_([-]?[0-9a-zA-Z]+)?/news_type_([-]?[0-9a-zA-Z]+)?.html$</from> <to type="forward">/web/news/newsParticular.do?nId=$1&newsType=$2</to> </rule> <!-- 新闻详细页结束 --> </urlrewrite>
页面 <body> <div class="content-right fr"> <div class="content-right-tit"> <img src="web/img/t34.jpg"/> </div> <div class="content-right-con"> <div class="news"> <div class="news-con1"> <p>企业公告</p> <ul> <c:forEach var="item" items="${corporateActionsLists }" > <li > <c:url value="/web/news/newsParticular/n_id_${item.id}/news_type_${item.newsType}.html" var="tempNewsUrl"></c:url> <a href="${tempNewsUrl} ">${item.newsTitle }</a><span>发布时间:<i><fmt:formatDate value="${item.releaseTime }" pattern="yyyy-MM-dd"/></i></span> </li> </c:forEach> </ul> </div> <div class="news-con2"> <p>行业新闻</p> <ul> <c:forEach var="item" items="${tradeNewsLists }" > <li> <c:url value="/web/news/newsParticular/n_id_${item.id}/news_type_${item.newsType}.html" var="tempNewsUrl"></c:url> <a href="${tempNewsUrl}">${item.newsTitle }</a><span>发布时间:<i><fmt:formatDate value="${item.releaseTime }" pattern="yyyy-MM-dd"/></i></span> </li> </c:forEach> </ul> </div> </div> </div> </div> </body>