改變Jsp文件後綴

web.xml 配置html

<servlet-mapping>
    <servlet-name>ChangSuffix</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>


servlet中的關鍵代碼java

String url=request.getRequestURL();  //獲取請求的URL
String rooturl=request.getContextPath(); //獲取項目的跟路徑
url=url.replace(rooturl,"").replaceFirst(".html",".jsp");  //將URL請求路徑進行替換
RequestDispatcher rd = request.getRequestDispatcher(url);
rd.forward(request,response); //頁面跳轉
相關文章
相關標籤/搜索