I'm trying to reproduce the solution given in this question but I'm still getting the same error.
Tomcat 7 keeps giving me a 404. What am I doing wrong?
This is the servlet code:
edu@ubuntu:~/ch1$ cat ch1servlet.java
package com.example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ch1servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html> " +"<body>" +"<h1 align=center>HF\'s Chapter1 Servlet</h1>" +" " + "<br>" + today + "</body>" + "</html>");
}
}
Which was compiled with:
edu@ubuntu:~/ch1/WEB-INF$ javac -classpath /usr/share/tomcat7/lib/servlet-api.jar -d classes ../ch1servlet.java
edu@ubuntu:~/ch1/WEB-INF$ ls classes/com/example/ch1servlet.class
classes/com/example/ch1servlet.class
This is the content of web.xml
edu@ubuntu:~/ch1/WEB-INF$ cat web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
>
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>com.example.ch1servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>
Then I copied the ch1 directory to $CATALINA_HOME/webapps
edu@ubuntu:~/ch1$ cd ..
edu@ubuntu:~$ ps -aux | grep tomcat
tomcat7 1053 0.3 11.3 2557684 85272 ? Sl 03:12 0:51 /usr/lib/jvm/java-8-oracle/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath /usr/share/tomca 7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start
edu 2259 0.0 0.1 11744 916 pts/1 S+ 07:24 0:00 grep --color=auto tomcat
edu@ubuntu:~$ sudo mkdir /usr/share/tomcat7/webapps
edu@ubuntu:~$ sudo cp -rf ch1/ /usr/share/tomcat7/webapps/
edu@ubuntu:~$ ls /usr/share/tomcat7/webapps/
ch1
edu@ubuntu:~$
When I try to access 192.168.1.45:8080/ch1/Serv1
I get the infamous 404 "The requested resource (/ch1/Serv1/) is not available"
This is the version of java I'm using:
edu@ubuntu:~$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
I repeated quite the same process from different tutorials about a dozen of times and I always get stuck in the same point.