JSP 站点 web.xml 问题 在 sevlet 映射中找不到 url-pattern /MyController 的页面
<?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>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>MyController</servlet-name>
<servlet-class>com.pk.MyController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>/MyController</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我有此配置,但无法访问 hzhfyp.com/MyController
(PAGE NOT FOUND
)
MyController
Servlet 的路径是 WEB -INF/classes/com/pk/MyController.class
虽然index.jsp
加载准确。此处演示 http://hzhfyp.com/
单击任何按钮都会生成在 Firebug(firefox) 中显示为找不到页面的 js 错误。
<?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>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>MyController</servlet-name>
<servlet-class>com.pk.MyController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>/MyController</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I have this configuration, but unable to access hzhfyp.com/MyController
(PAGE NOT FOUND
)
The Path for MyController
servelet is WEB-INF/classes/com/pk/MyController.class
Although index.jsp
is loaded accuratelty. Demo here http://hzhfyp.com/
Clicking any button will generate js error visible in Firebug(firefox) as Page not Found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
URL 区分大小写。您已使用
M
将其映射到/MyController
上,但您的 jQuery 代码通过/myController
使用m
调用它>。相应地修复它。至于尽管 URL 正确却返回 404 的 servlet,当 servlet 初始化失败或根本没有部署正确的
web.xml
时,可能会发生这种情况。阅读服务器启动日志以了解 servlet 初始化期间是否存在任何错误,并验证您是否使用正确的web.xml
进行部署。URLs are case sensitive. You've mapped it on
/MyController
withM
, but your jQuery code is calling it by/myController
withm
. Fix it accordingly.As to the servlet returing a 404 in spite of the correct URL, this can happen when the servlet failed to initialize or when you didn't deploy the correct
web.xml
at all. Read the server startup logs for any errors during servlet initialization and verify if you're deploying with the rightweb.xml
.