java - 为什么在 web.xml 文件中隐藏 .jsp 扩展名时出现 404 错误?

标签 java apache jsp tomcat servlets

我在 web.xml 文件中配置了我所有的 JSP 页面以隐藏 .jsp 扩展名,并且由于 SEO 的观点,我在 web.xml 文件中创建了对应于每个 JSP 页面的自定义 URL,但是当我在服务器 tomcat 上部署这个应用程序时在 Apache 网络服务器下运行,所以我的服务器团队这样回复我,但我不明白他们的意思。

Please note that you are running in a server where apache is the web server and Tomcat is a servlet container. This way all static requests such as images, CSS, js, HTML are handled by apache and jsp, servlets are handled by Tomcat. This means Apache will forward any request that you send with the following extension to tomcat

.jsp 
/servlet 
.do

This means in order for Tomcat to execute your code you need to send a request to apache as .jsp, /servlet and .do. Once you send this way, it will automatically send to tomcat to running there. In your case /hosting will be executed by apache only and that's why you get this error of 404.

web.xml

<servlet>
   <servlet-name>domain</servlet-name>
   <jsp-file>/domain-registration.jsp</jsp-file>
</servlet>
<servlet-mapping>
   <servlet-name>domain</servlet-name> 
   <url-pattern>/domain-registration</url-pattern>
</servlet-mapping>

最佳答案

请给出正确的错误,您在哪个网址上收到 404?

尝试您已经在 web.xml 中指定的任何其他 url 模式,检查它是否正常工作。我认为您的 web.xml 文件中存在一些语法错误,否则它应该可以工作。

关于java - 为什么在 web.xml 文件中隐藏 .jsp 扩展名时出现 404 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46522617/

相关文章:

java - 如何在 Android 上升级 Apache HttpClient 版本

java - 将数据库中的数据显示到文本框中

spring - 从 JSP 文件中的 session 范围 bean 访问数据

JavaServlet : set an instance as an attribute

java - KeyTyped 方法说 TextField 为空...但实际上不是

java - 方法签名中的...是什么

php - 调用未定义函数 mysql_connect() Apache + Mysql 错误

apache - 对 SSLCaCertificateFile 包感到困惑

java - 基于交叉点创建多边形

java - 使用 java 流根据特定检查更新对象