gpt4 book ai didi

java - 上下文路径未在 tomcat 5 中设置

转载 作者:行者123 更新时间:2023-11-28 23:34:25 25 4
gpt4 key购买 nike

我们的一个项目部署在 tomcat 5.5 中。我们的代码不是 war 文件。部署为一个 jar 。而且我们没有直接部署在 webapps 下。我们创建了新文件夹并将所有内容放在那里。我们在 server.xml 中的上下文标记下配置了该路径

<code>
< Context path="/ABC" docBase="/app/apache-tomcat-5.5.26/webapps/ABC/"
debug="1" reloadable="true" crossContext="true">

< /Context>
</code>

问题是。我们能够登陆主页,但图像未加载且所有链接均无效主页链接;//ip:端口/ABC/home.jsp

当我们单击任何链接时,上下文路径将被删除,如下所示链接之一://ip:port/firSTLink.jsp

请帮助我在哪里我们必须配置上下文路径

提前致谢

最佳答案

您的链接 <a href="/home.jsp">对您的域来说是绝对的,您需要在 URL 中包含上下文。要获取当前上下文,请使用 request.getContextPath

getContextPath

String getContextPath()

Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

...

Returns: a String specifying the portion of the request URI that indicates the context of the request

HttpServletRequest#getContextPath()

您可以使用 ${pageContext.request.contextPath} 在 JSP 中检索此值.您的链接应该是:

<a href="${pageContext.request.contextPath}/home.jsp">Home</a>

关于java - 上下文路径未在 tomcat 5 中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25931170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com