Set Tomcat Default Context Path

六月ゝ 毕业季﹏ 提交于 2019-12-07 07:13:12

问题


In my context.xml file I set the following to: <Context antiJARLocking="true" path="/" />

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


回答1:


It sounds like you are building your war file as "appName.war". That is the reason tomcat deploys it under "/appName".

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/




回答2:


Some apps are written such that changing the context path would require code changes. If you have that situation here is another way to make your server default to a specific context:

Step 1) Put this in [tomcat]/conf/web.xml

<welcome-file-list>      
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

Step 2) Add this file to your ROOT webapp folder, and leave everything else the same: index.html (for root app). Using this javascript approach rather than a normal redirect, allows the 'redirection' to work AND KEEP the same url parameters.

<!doctype html>
<html>
<head>

<script language="JavaScript">
    document.location.href = "/mycontext" + document.location.search;
</script>

</head>

</html>



回答3:


Use this Maven plugin:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <path>/</path>
        <warFile>${project.build.directory}/fileName.war</warFile>
    </configuration>
</plugin>

Delete the context.xml file in your META-INF folder.

Run your project with this command: mvn tomcat7:run



来源:https://stackoverflow.com/questions/13640247/set-tomcat-default-context-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!