Servlet 上下文 URL
我在 JBoss AS 中部署了一个名为 test
的战争。
当我进入浏览器并输入 URL http://localhost:8080/test
时,我会看到 login.jsp
页面,这是欢迎页面。
当我点击提交按钮时,将调用名称 CheckLoginServlet
的 servlet(onSubmit
我已重定向到 /test/servlet/CheckLoginServlet
)。成功登录后,此 servlet 重定向到 docroot/main/jsp
内的 jsp (MFrame.jsp
)。该网址看起来像这样 http://localhost:8080/main/jsp/MFrame.jsp?sid=13045798560
,我收到 404 错误。
原因是 url 不包含上下文 test
,现在当我在浏览器中显式修改 url 以在其中包含 test 时(现在 url 看起来像 http://localhost: 8080/test/main/jsp/MFrame.jsp?sid=13045798560
),页面渲染成功。
我的问题是为什么上下文 test
没有出现在 url 中,因为它是上下文根。
I deployed a war named test
in the JBoss AS.
When i go to browser and type the url http://localhost:8080/test
, i get the login.jsp
page, which is the welcome page.
When i hit the submit button a servlet gets invoked name CheckLoginServlet
(onSubmit
i have redirected to /test/servlet/CheckLoginServlet
). On successful login this servlet redirects to a jsp (MFrame.jsp
) which is inside the docroot/main/jsp
. The url looks like this http://localhost:8080/main/jsp/MFrame.jsp?sid=13045798560
, and i get a 404 error.
The reason is that the url is not including the context test
, now when i explicitly modify the url in the browser to include test in it (now the url looks like http://localhost:8080/test/main/jsp/MFrame.jsp?sid=13045798560
), the page successfully renders.
My question is why the context test
is not coming in the url, as it is the context root.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重定向是与网络服务器相关的。因此,如果您有
.sendRedirect("/main/jsp/MFrame.jsp")
,则上下文路径将被省略。这是因为重定向是一个 HTTP 概念,并且它们发生在浏览器中(它们称为客户端重定向)您有几个选项:
req.getRequestDispatcher("/main/jsp/MFrame.jsp") .forward(req, res);
- 这将触发服务器端重定向,并且它是上下文相关的,request.getContextPath()
)Redirects are web-server relatives. So If you have
.sendRedirect("/main/jsp/MFrame.jsp")
, the context path will be omitted. That's because redirects are an HTTP notion and they happen in the browser (they are called client-side redirects)You have a couple of options:
req.getRequestDispatcher("/main/jsp/MFrame.jsp").forward(req, res);
- this will trigger a server-side redirect, and it is context-relativerequest.getContextPath()
)