我使用 eclipse j2ee 创建了一个 web 项目,并使用了 tomcat 服务器。在eclipse中,当我运行服务器时,项目运行正常。但是当我将项目文件夹放入/webapps
tomcat时找不到我的index.jsp
,除非我将index.jsp放在项目的根文件夹中。
那么,我应该把index.jsp
文件放在哪里呢?
不是直接将项目文件夹放入/webapps
,而是从 eclipse 创建一个 .WAR 文件并将其放入 tomcat/webapps
文件夹中。Tomcat 将部署应用程序。
如果您将项目放入webapps
正在运行的服务器的文件夹中,tomcat
则可以通过context path
在application
.
通常context path
以应用程序目录命名。因此,例如,如果您将名为的目录app
放在您的webapps
文件夹中,并且您在标准端口上的主机上tomcat
运行服务器,则可以通过以下方式访问它:tomcat
8080
http://localhost:8080/app/index.jsp
如果manager
您正在服务器上运行应用程序,tomcat
您可以访问它并通过访问 url 查看正在运行的应用程序列表:
http://localhost:8080/manager/html/list
要访问manager
应用程序,您需要在tomcat-users.xml
文件中有一个有效用户。
Eclipse
WebProject
或J2EE
项目创建一个WebContent
与src
.
在部署到Tomcat
任何其他相关联的过程中WebServer
,它首先创建一个war
webapp 文件夹结构,然后将所有WebContent
文件夹内容复制到并webapps
从其中编译Java
类。src
webapps\web-inf\classes
您需要的是放入index.jsp
文件夹并在元素下WebContent
具有所需的映射。web.xml
welcome-files
除非您在 web.xml 文件中正确提及,否则无论您将 index.jsp 放在何处,它都不会受到影响。
例如假设您的 index.jsp 在 webapps/project/file 中,那么您应该以这种方式写入 web.xml
<welcome-file>file/index.jsp</welcome-file>
</welcome-file-list>
假设它在另一个文件夹 webapps/project/file/file1
<welcome-file>file/file1/index.jsp</welcome-file>
</welcome-file-list>
假设 index.jsp 在 webapps/project/index.jsp 那么 web.xml 将是
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>