【发布时间】:2013-01-22 15:02:53
【问题描述】:
当我将应用程序文件夹放在 {JETTY_HOME}/webapps 目录中时,我有一个运行正常的 Web 应用程序(调用了 servlet)。
如果我将 Web 应用程序的副本放在 webapps 的子文件夹中,那么当我浏览到该站点时会调用所有静态文件,但我通过 ajax 调用的 servlet 返回 404。
http://localhost/shlaa
- 正确调用 /shlaa/CommentController.do 没有错误。
http://localhost/mapapp/shlaa
-
为 ajax 调用 /mapapp/shlaa/CommentController.do 返回 404
两个路径 /WEB_INF 文件夹中的 web.xml 包含以下内容
<servlet> <servlet-name>CommentController</servlet-name> <servlet-class>web.CommentController</servlet-class> </servlet> <servlet-mapping> <servlet-name>CommentController</servlet-name> <url-pattern>/CommentController.do</url-pattern> </servlet-mapping>{JETTY_HOME}/etc 中的 jetty.xml 文件夹包含以下内容:
<Call class="org.mortbay.jetty.webapp.WebAppContext" name="addWebApplications"> <Arg><Ref id="contexts"/></Arg> <Arg><SystemProperty name="jetty.home" default="."/>/webapps</Arg> <Arg><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Arg> <Arg type="boolean">True</Arg> <!-- extract --> <Arg type="boolean">True</Arg> <!-- parent priority class loading --> </Call>
【问题讨论】:
-
我注意到您的 servlet 模式中的 .do 扩展名。您是否有机会使用 struts ?
-
你也说过localhost/shlaa 正确调用/mapapp/shlaa/CommentController.do 没有错误。你能分享一下配置吗?我很好奇它是如何工作的
-
@Zenil 不使用 struts - 只是养成了用这个结束 servlet 引用的习惯。
-
@Zenil 我已经在 webapps 根目录和 webapps/mapapp 目录中放置了一个 shlaa 的克隆应用程序,我已经更正了上面的参考
-
在第一种情况下,您说它可以正常工作:localhost/shlaa 调用 /mapapp/shlaa/CommentController.do 。我想知道 这是如何 工作的。你的 web.xml 配置是什么?
标签: java servlets jetty url-routing directory-structure