【问题标题】:Can't get a .jsp file to run on Tomcat 7 ubuntu server无法在 Tomcat 7 ubuntu 服务器上运行 .jsp 文件
【发布时间】:2014-07-12 17:52:09
【问题描述】:

我使用apt-get 在我的 Ubuntu 12.04 服务器上安装了 Tomcat 7。 据我了解,我只需要上传包含.jsp 文件的项目目录和包含web.xml 文件的WEB-INF 目录。

基本路径:/usr/share/tomcat7-root/default-root/test/

index.jsp:/usr/share/tomcat7-root/default-root/test/index.jsp

web.xml:/usr/share/tomcat7-root/default-root/test/WEB-INF/web.xml

index.jsp 文件内容:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
</head>
<body>
    <% out.println("this is a test"); %>
</body>

web.xml 内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>test</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

当我去

mydomain:8080/test/index.jsp

我收到以下错误:

HTTP 状态 404 - /test/index.jsp

输入状态报告

消息/test/index.jsp

说明请求的资源(/test/index.jsp)不可用。

Apache Tomcat/7.0.26

我是否导航到了正确的目录? Tomcat 登陆页面加载 its fine! 页面没有错误,所以我假设 Tomcat 运行正常。

我的 web.xml 属性或文件结构有问题吗?

编辑 - 错字

【问题讨论】:

    标签: java apache jsp tomcat ubuntu


    【解决方案1】:

    在 Ubuntu 服务器上使用 apt-get 的 Tomcat 7 的正确目录是 /var/lib/tomcat7/webapps/ROOT/

    【讨论】:

      【解决方案2】:

      这里有两个问题:

      1. WEB-INF,而不是WEB_INF(破折号,不是下划线)
      2. 您的 Web 应用程序应位于 webapps 目录下。

      所以,在/usr/share/tomcat7-root/default-root/webapps下:

      1. 创建目录test
      2. 复制jsp文件到test
      3. test下创建目录WEB-INF
      4. 复制web.xml到WEB-INF

      【讨论】:

      • 1.那只是一个stackoverflow错字,对不起。 2. 显然那不是tomcat7 根目录。我设法在这里找到了它:/var/lib/tomcat7/webapps/ROOT/,一切都按预期工作。不过感谢您的关注。
      • 这样的话,如果你想让web应用对应/test,只需在/var/lib/tomcat7/webapps下创建一个test目录
      【解决方案3】:

      我很确定您的问题在于您对基础浴的概念以及您将 web.xml 放在错误的位置。如果 /default-root 是基本路径,web.xml 应该放在这里:

      /usr/share/tomcat7-root/default-root/WEB_INF/web.xml
      

      在默认根网络应用程序的根目录中。

      但我认为 tomcat 7 的默认 web 应用是 ROOT 而不是 default-root,不是吗?

      一旦你解决了,我想点击网址:

      http:localhost:8080/test/index.jsp 
      

      然后就可以工作了。

      如果您希望欢迎文件正常工作,则需要将 web.xml 更新为:

       <welcome-file>/test/index.jsp</welcome-file>
      

      【讨论】:

        猜你喜欢
        • 2012-07-25
        • 2020-05-16
        • 1970-01-01
        • 2021-06-27
        • 1970-01-01
        • 2012-10-15
        • 2017-09-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多