部署描述符问题
我正在尝试将应用程序加载到本地 tomcat 实例。当我在启动 tomcat 后将地址输入到 URL 栏中时,即使资源在那里,我也会收到 404 未找到错误。我做了很多尝试和错误,并在 DD 文件中找到了一些东西。部署描述符的一部分包含以下代码。
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
当我从 web.xml 文件中注释这部分时,我能够成功地从浏览器获取资源。所以我很确定问题出在这段代码中,但我无法理解它是什么。有人可以解释一下这段代码在做什么以及为什么我会遇到错误吗?提前致谢。
编辑:根据记录,我试图直接访问根文件夹下的资源。 .. http://localhost/myapp/index.jsp
I am trying to load an application to my local tomcat instance. When I input the address into the URL bar after starting tomcat I'm getting 404-not found error even though the resources were there. I did a lot of trial and error and found something in the DD file. A portion of the deployment descriptor contains following code..
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
When I comment this part from the web.xml file I was able to successfully get to the resources from the browser. So I'm pretty sure that the problem is in this code but I can't understand what it is. Can someone please explain what this code is doing and why am I getting error with this.? Thanks in advance.
Edit: For the record, I was trying to access resources directly under root folder. .. http://localhost/myapp/index.jsp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是旧版 Tomcat 特定的
InvokerServlet
它存在于 Apache Tomcat 的古老版本中(并且在糟糕且过时的教程/书籍中仍然提到)。在黑暗时代,人们可以调用 servlet,而无需将它们映射到web.xml
中。您只需在 URL 中的/servlet
路径后输入完全限定的 servlet 类名。后来证实这是一个安全漏洞并且容易受到攻击。它在 2002 年左右的 Tomcat 5.0 中被禁用和弃用(!),并在 2009 年左右的 Tomcat 7.0 中被删除。
您可以安全地删除它。它没有增加任何价值。从 Tomcat 7.0 / Servlet 3.0 开始,您甚至不再需要在
web.xml
中映射 servlet。您可以使用@WebServlet
注释代替。至于删除它后它为何有效的具体问题,您可能使用了错误的 URL。也许您也将上下文根路径称为
servlet
?That's the legacy Tomcat-specific
InvokerServlet
which was present in ancient versions of Apache Tomcat (and still mentioned in poor and outdated tutorials/books). It was in the dark ages used to be able to invoke servlets without the need to map them inweb.xml
. You just have to enter the fully qualified servlet classname in the URL after the/servlet
path.It was later confirmed that it was a security hole and vulrenable to attacks. It was disabled and deprecated on Tomcat 5.0 around 2002(!) and removed in Tomcat 7.0 around 2009.
You can safely remove it. It adds no utter value. Since Tomcat 7.0 / Servlet 3.0 you even don't need to map servlets in
web.xml
anymore. You can use the@WebServlet
annotation instead.As to the concrete problem why it works after you removed it, you'll probably have used the wrong URLs. Maybe you've called your context root path also
servlet
?