英文:
Apache Tomcat is showing an already made WAR file instead of the home page at localhost:8080
问题
你好,我正在尝试通过WAR文件将我的项目提交给我的指导老师。我已经创建了WAR文件,并且正在尝试检查WAR文件是否有效。但是当我运行Tomcat并在浏览器中输入 localhost:8080
时,WAR文件被部署,而不是显示首页。
英文:
Hello I am trying to pass my project to my instructor through war file. I have already made the war file and I am trying to check if the war file works. But when I run the tomcat and input the localhost:8080
in the browser a WAR file is being deployed instead of the home page
答案1
得分: 2
可能你是在使用你的讲师定制过的 Tomcat 版本。
通常情况下,当你从互联网上下载一个“原样”的 Tomcat 时,你应该创建一个 WAR 文件(比如 calculator.war
),并将其放入 webapps
文件夹中,然后你就可以通过 localhost:8080/calculator
访问它。这是默认行为,但仍然有可能部署你定制的 WAR 文件,使其可以通过 localhost:8080
访问,就像你所描述的那样。
有几种方法可以实现这样的部署,但在你的情况下,似乎在 $CATALINA_HOME$\conf\server.xml
文件中有如下条目:
<Host name="localhost" appBase="webapps" unpackWARs="true"
autoDeploy="false" deployOnStartup="false">
<Context path="" docBase="Calculator"></Context>
....
</Host>
或者,你可能有一个位于 $CATALINA_HOME\conf\Catalina\localhost\ROOT.xml
文件中的文件,其中包含关于 Calculator
WAR 文件的信息。
另一个需要检查的方向是,在你的集成开发环境中,你是否将 Calculator
项目创建成了 ROOT.war
。这也是将内容部署在根路径上的一种方式。
总之,我建议你阅读这个教程,因为很有可能你正在使用这些部署方法中的其中一种。
英文:
Probably you work with a tomcat version customized by your instructor.
By default when you take a tomcat downloaded from the internet "as-is" you should create a WAR (say, calculator.war
) and put into webapps
folder and after that you'll be able to access it by localhost:8080/calculator
. That's the default behavior, but its still possible to deploy your custom war to be accessible through localhost:8080
as you've described.
There are a couple of ways to do so, but it looks like in your case there is an entry in $CATALINA_HOME$\conf\server.xml
that looks something like this:
<Host name="localhost" appBase="webapps" unpackWARs="true"
autoDeploy="false" deployOnStartup="false">
<Context path="" docBase="Calculator"></Context>
....
</Host>
Or alternatively you have $CATALINA_HOME\conf\Catalina\localhost\ROOT.xml
file
that contains information about the Calculator
war.
Another direction to check is that in your IDE you don't create ROOT.war
out of your Calculator
project. This is also a way to deploy stuff in the root context path.
All-in-all I suggest you reading This tutorial because the chances are that you somehow use one of these methods of deployment.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论