设置Tomcat默认上下文路径
在我的 context.xml
文件中,我将以下内容设置为:< Context antiJARLocking =truepath =//>
In my context.xml
file I set the following to: <Context antiJARLocking="true" path="/" />
当我从NetBeans运行我的项目时,它可以正常工作并转到 http:// localhost:8080 /登录
。然后当我清洁&构建并进入Tomcat Manager并部署war文件,因为某些原因它会转到 http:// localhost:8080 / appName / login
。我不知道为什么它添加上下文路径或甚至从它获取它,但是当我手动部署它,这样做。当我直接从Netbeans运行项目时,它不会。在直接从NetBeans运行它之后,如果我去Tomcat管理器,那么它显示在上下文路径 /
中部署的应用程序是正确的。当我手动部署.war时,它会根据上下文路径 / appName
When I run my project from NetBeans then it works correctly and goes to http://localhost:8080/login
. Then when I clean & build and go into Tomcat Manager and deploy the war file, for some reason it goes to http://localhost:8080/appName/login
. I'm not sure why it's adding the context path or where it even gets it from but when ever I deploy it manually it does that. When ever I run the project directly from Netbeans then it doesn't. After I run it directly from NetBeans, if I go to Tomcat Manager then it shows the app deployed under context path /
which is correct. When I deploy the .war manually then it deploys under context path /appName
听起来你正在将你的战争文件建立为appName.war。这就是tomcat在/ appName下部署它的原因。
It sounds like you are building your war file as "appName.war". That is the reason tomcat deploys it under "/appName".
如果您希望您的应用程序可访问/,您可以将war文件重命名为ROOT.war,并将其放在/ webapps中,并且可以在http:// localhost:8080 /
If you want your application accessible at /, you can rename your war file as ROOT.war and drop it in /webapps and it should be accessible at http : //localhost:8080/