1

我使用 eclipse j2ee 创建了一个 web 项目,并使用了 tomcat 服务器。在eclipse中,当我运行服务器时,项目运行正常。但是当我将项目文件夹放入/webappstomcat时找不到我的index.jsp,除非我将index.jsp放在项目的根文件夹中。

那么,我应该把index.jsp文件放在哪里呢?

4

4 回答 4

2

不是直接将项目文件夹放入/webapps,而是从 eclipse 创建一个 .WAR 文件并将其放入 tomcat/webapps文件夹中。Tomcat 将部署应用程序。

于 2013-09-20T07:42:35.337 回答
0

如果您将项目放入webapps正在运行的服务器的文件夹中,tomcat则可以通过context pathapplication.

通常context path以应用程序目录命名。因此,例如,如果您将名为的目录app放在您的webapps文件夹中,并且您在标准端口上的主机上tomcat运行服务器,则可以通过以下方式访问它:tomcat8080

http://localhost:8080/app/index.jsp

如果manager您正在服务器上运行应用程序,tomcat您可以访问它并通过访问 url 查看正在运行的应用程序列表:

http://localhost:8080/manager/html/list

要访问manager应用程序,您需要在tomcat-users.xml文件中有一个有效用户。

于 2013-09-20T07:44:20.513 回答
0

Eclipse WebProjectJ2EE项目创建一个WebContentsrc.

在部署到Tomcat任何其他相关联的过程中WebServer,它首先创建一个warwebapp 文件夹结构,然后将所有WebContent文件夹内容复制到并webapps从其中编译Java类。srcwebapps\web-inf\classes

您需要的是放入index.jsp文件夹并在元素下WebContent具有所需的映射。web.xmlwelcome-files

于 2013-09-20T07:53:50.203 回答
0

除非您在 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>
于 2013-09-20T08:03:52.483 回答