web.xml 和相对路径

发布于 2024-07-06 09:12:39 字数 431 浏览 3 评论 0原文

在web.xml中,我将欢迎文件设置为index.jsp内web.xml中的jsp,

<welcome-file>WEB-INF/index.jsp</welcome-file>

然后转发到servlet,

<% response.sendRedirect(response.encodeRedirectURL("myServlet/")); %>

但是应用程序尝试在以下路径中找到servlet,

applicationName/WEB-INF/myServlet

问题是web-inf不应该在路径。 如果我将index.jsp移出web-inf,那么问题就解决了,但是还有其他方法可以解决这个问题吗?

in web.xml i set my welcome file to a jsp within web.xml

<welcome-file>WEB-INF/index.jsp</welcome-file>

inside index.jsp i then forward on to a servlet

<% response.sendRedirect(response.encodeRedirectURL("myServlet/")); %>

however the application tries to find the servlet at the following path

applicationName/WEB-INF/myServlet

the problem is that web-inf should not be in the path. If i move index.jsp out of web-inf then the problem goes but is there another way i can get around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

说不完的你爱 2024-07-13 09:12:39
<% response.sendRedirect(response.encodeRedirectURL("/myServlet/")); %>`

由于 jsp 是从 WEB-INF 目录提供的,因此 servlet url 也是从该相对路径解析的。 在前面添加 / 将从上下文根解析 url

<% response.sendRedirect(response.encodeRedirectURL("/myServlet/")); %>`

since the jsp is served from the WEB-INF directory the servlet url is also resolved from that relative path. adding a / before will resolve the url from the context root

尤怨 2024-07-13 09:12:39

据我了解,WEB-INF 是一个特殊的文件夹,包含 JSP 使用的配置和类,您不应该将用于直接服务的代码放入其中。

不管怎样,你尝试过 /myServlet 吗?

As I understand it, WEB-INF is a special folder containing configuration and classes used by your JSPs, you shouldn't put code intended for direct serving inside it.

Anyhow, have you tried /myServlet?

妄断弥空 2024-07-13 09:12:39

您是否尝试过使用绝对路径来做到这一点?

response.sendRedirect(response.encodeRedirectURL("/myServlet/"));

Have you tried to do it with the absolute path ?

response.sendRedirect(response.encodeRedirectURL("/myServlet/"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文