如何隐藏.jsp扩展名或更改URL上的显示名称?
我正在使用servlet-jsp通信。我的web.xml代码是
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>pub</servlet-name> <jsp-file>/publications.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>pub</servlet-name> <url-pattern>/publications</url-pattern> </servlet-mapping> <servlet> <servlet-name>SciArchive</servlet-name> <servlet-class>controller.SciArchiveController</servlet-class> </servlet> <servlet-mapping> <servlet-name>SciArchive</servlet-name> <url-pattern>*.sci</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>home.jsp</welcome-file> </welcome-file-list> </web-app>
我想在网址中隐藏.jsp扩展名..../SciArchive/publications.jsp 以..../SciArchive/publications
..../SciArchive/publications.jsp
..../SciArchive/publications
您已经publications.jsp映射到URL模式。为什么不使用此URL模式访问jsp。?
publications.jsp
<servlet> <servlet-name>pub</servlet-name> <jsp-file>/publications.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>pub</servlet-name> <url-pattern>/publications</url-pattern> <!-- Use this URL --> </servlet-mapping>
如果单击URL http://somehost/SciArchive/publications,它将自动在后台调用jsp,URL将保持不变(没有页面名称,即没有.jsp)。
http://somehost/SciArchive/publications