Java 隐藏 .jsp 扩展名或更改 URL 上的显示名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20326451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide .jsp extension or change display name on URL
提问by Hareesh
How to hide .jsp extension or change display name on URL?
如何隐藏 .jsp 扩展名或更改 URL 上的显示名称?
I'm using servlet-jsp communication. my web.xml code is
我正在使用 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>
I want to hide .jsp extenstion in URL ..../SciArchive/publications.jsp
to ..../SciArchive/publications
我想隐藏的.jsp extenstion的URL..../SciArchive/publications.jsp
来..../SciArchive/publications
采纳答案by Saif Asif
You already have publications.jsp
mapped to a URL-pattern. Why are you not using this URL pattern to access the jsp. ?
您已经publications.jsp
映射到 URL 模式。你为什么不使用这个 URL 模式来访问 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>
If you hit the URL http://somehost/SciArchive/publications
, it will automatically call your jsp in the back-ground and the URL will remain the same (without the page name i.e without .jsp).
如果你点击 URL http://somehost/SciArchive/publications
,它会在后台自动调用你的 jsp 并且 URL 将保持不变(没有页面名称,即没有 .jsp)。