Tomcat 6到Tomcat 7导致上下文路径停止协作 [英] Tomcat 6 to Tomcat 7 causes context path to stop cooperating
问题描述
我有一个可在Tomcat 6中流畅运行的Web应用程序.假设它在server:8282/MyApplication
上运行.我有一个如下所示的上下文xml:
I have a webapp that is working swimmingly in Tomcat 6. Let's say it's running on server:8282/MyApplication
. I have a context xml that looks like this:
<Context crossContext="true"
debug="5"
docBase="MyApplication"
path="MyApplication"
reloadable="true">
在我的应用程序中,我的链接看起来像
In my application, my links look like
server:8282/MyApplication/myAction.do?params=blah
当我将其切换到Tomcat 7时,似乎将链接更改为:
When I switch it to Tomcat 7, it seems to change the link to:
server8282/myAction.do?params=blah
我没有更改应用程序中的任何内容,两个地方的代码都是相同的.我可以更改一些全局设置来重新获得"MyApplication"吗?
I haven't changed -anything- in the application, it's the same code in both places. Is there some global setting I can change to get that "MyApplication" back in?
例如,生成链接的代码为:
the code that generates the link is, as an example,:
<a href="<%=request.getContextPath() %>/myAction.do?params=blah">do the blah</a>
推荐答案
部署过程似乎出了点问题,由于某种原因,Tomcat试图在服务器的根目录上为您的应用程序提供服务,因为您的${pageContext.request.contextPath}
返回空.
Seems like something is wrong with your deploying process, and for some reason Tomcat is trying to serve your application at the root of the server, because of that your ${pageContext.request.contextPath}
is returning empty.
由于我不确定您的确切部署要求,请尝试以下过程之一.为了确保避免配置冲突,请在全新的Tomcat 7安装上进行操作:
Since I'm not sure of your exactly deployment requirements, try one of the following procedures. Just to be sure and avoid configuration conflicts, do it on a brand new Tomcat 7 installation:
- 如果您有一个
MyApplication.war
文件,只需将其放在<CATALINA_HOME>\webapps
上,请勿使用任何上下文文件(请注意war文件中的上下文文件,即/META-INF/context.xml
) - 如果您有爆炸的应用程序,请在
webapps
内创建一个文件夹MyApplication
,然后将应用程序内容放在此处(同样,没有context.xml
).
- If you have a
MyApplication.war
file just drop it at<CATALINA_HOME>\webapps
, do not use any context files (be ware of context files inside the war file, i.e.,/META-INF/context.xml
) - If you have an exploded application, create a folder
MyApplication
insidewebapps
and drop the application contents there (again, nocontext.xml
).
如果您确实需要将应用程序保留在webapps
之外:
If you really need to keep your application outside of webapps
:
-
在
<Host>
内的<CATALINA_HOME>\conf\server.xml
中添加一个新的Context
元素:
Add a new
Context
element to<CATALINA_HOME>\conf\server.xml
inside<Host>
:
<Context path="/MyApplication"
docBase="/absolute/physical/path/to/MyApplication"
reloadable="true"
crossContext="true">
<CATALINA_HOME>\Catalina\localhost
中创建一个MyApplication.xml
文件.
MyApplication.xml
file in <CATALINA_HOME>\Catalina\localhost
with the content mentioned above.有关更多信息,请参考上下文容器文档.
For further info refer to The Context Container documentation.
这篇关于Tomcat 6到Tomcat 7导致上下文路径停止协作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!