There have been multiple questions like this on SO, but none of those solved my problem and I can't think of anything left that might cause this error.
I'm trying to write a simple servlet that just prints "Hello World":
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class PrintServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
What I did was compile the java file, move the compiled file into /usr/local/apache-tomcat-7.0.65/webapps/examples/WEB-INF/classes
, then add these to the web.xml file located at /usr/local/apache-tomcat-7.0.65/webapps/examples/WEB-INF
:
<servlet>
<serlet-name>PrintServlet</servlet-name>
<servlet-class>PrintServlet</servlet-name>
</servlet>
<servlet-mappinng>
<servlet-name>PrintServlet</servlet-name>
<url-pattern>/servlet/PrintServlet</url-pattern>
</servlet-mapping>
And tried to access the servlet using http://localhost:8080/servlet/PrintServlet
.
And I get the error message: Status 404 The requested resource is not available.
I don't see where there could be a mistake, I'm simply following tutorials. Can anybody help me please?
EDIT:
log file at catalina.out (got this by calling tail -f catalina.out, not sure how else to open this file).
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/examples has finished in 130 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/host-manager
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/host-manager has finished in 80 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/manager
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/manager has finished in 96 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/ROOT
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/ROOT has finished in 62 ms
Dec 10, 2015 4:46:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 10, 2015 4:46:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 918 ms
Startup message when calling ./startup.sh:
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.65
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.65
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.65/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
Using CLASSPATH: /usr/local/apache-tomcat-7.0.65/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.65/bin/tomcat-juli.jar
Tomcat started.