我使用apt-get
在我的Ubuntu 12.04服务器上安装了Tomcat 7。
据我了解,我只需要上传包含.jsp
文件和WEB-INF
目录的项目目录。
基本路径:web.xml
index.jsp:/usr/share/tomcat7-root/default-root/test/
web.xml:/usr/share/tomcat7-root/default-root/test/index.jsp
index.jsp文件内容:
/usr/share/tomcat7-root/default-root/test/WEB-INF/web.xml
web.xml内容:
<%@ 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>
当我去
MYDOMAIN:8080 /测试/ index.jsp的
我收到以下错误:
HTTP状态404 - /test/index.jsp
输入状态报告
message /test/index.jsp
description请求的资源(/test/index.jsp)不可用。
Apache Tomcat / 7.0.26
我导航到了正确的目录吗? Tomcat登录页面加载<?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>
页面没有错误,因此我假设Tomcat正常运行。
我是否对web.xml属性或文件结构做错了什么?
编辑 - 拼写错误
答案 0 :(得分:3)
在Ubuntu服务器上使用apt-get
的Tomcat 7的正确目录是/var/lib/tomcat7/webapps/ROOT/
。
答案 1 :(得分:1)
这里有两个问题:
WEB-INF
,而非WEB_INF
(短划线,不是下划线)webapps
目录下。所以,在/usr/share/tomcat7-root/default-root/webapps
下:
test
test
test
创建目录WEB-INF
WEB-INF
答案 2 :(得分:0)
我很确定你的问题在于你的基本浴和你的把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>