3
votes

I installed Tomcat 7 on my Ubuntu 12.04 server using apt-get. As I understand it I just need to upload the project directory containing the .jsp file and WEB-INF directory containing the web.xml file.

The base path: /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

The index.jsp file contents:

<%@ 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>

The web.xml contents:

<?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>

When I go to

mydomain:8080/test/index.jsp

I get the following error:

HTTP Status 404 - /test/index.jsp

type Status report

message /test/index.jsp

description The requested resource (/test/index.jsp) is not available.

Apache Tomcat/7.0.26

Have I navigated to the correct directory? The Tomcat landing page loads the its fine! page with no errors so I'm assuming Tomcat is running properly.

Am I doing something wrong with the web.xml attributes or the file structure?

edit - typo

3

3 Answers

3
votes

The correct directory for Tomcat 7 using apt-get on Ubuntu server is /var/lib/tomcat7/webapps/ROOT/.

1
votes

You have two problems here:

  1. It's WEB-INF, not WEB_INF (a dash, not an underscore)
  2. Your web applications should go under webapps directory.

So, under /usr/share/tomcat7-root/default-root/webapps:

  1. Create directory test
  2. Copy jsp file to test
  3. Under test create directory WEB-INF
  4. Copy web.xml to WEB-INF
0
votes

I'm pretty sure that your problem is with your notion of the base bath and your putting web.xml in the wrong place. If /default-root is the base path, web.xml should go here:

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

at the root of the default root web app.

But I think the default web app for tomcat 7 is ROOT not default-root, no?

Once you get that worked out, I think hitting the url:

http:localhost:8080/test/index.jsp 

will then work.

If you want the welcome file to work then you'll need to update web.xml to something like:

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