In Apache Tomcat/9.0.14, I created very simple servlet to run, but get error:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
I followed this post: https://www.studytonight.com/servlet/steps-to-create-servlet-using-tomcat-server.php
I installed tomcat Tomcat/9.0.14 in redhat 6.9 with jdk1.8.0_151.
I also tried the same in my desktop windows 10.
When I follow the steps in above post , and tried to run the servlet direct with url "localhost:8080\First\hello", I got error as below:
HTTP Status 404 – Not Found
Type Status ReportMessage /hello
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.14
The web.xml as below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0" xmlns="java.sun.com/xml/ns/javaee" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="java.sun.com/xml/ns/javaee java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>pl.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
After compile there is MyServerlet.class in folder:
/opt/tomcat/webapps/First/WEB-INFO/classes/pl.
I already read the post here:
Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available”
I did not use any IDE like Eclipse or J_Builder . I just follow above post and build this servlet to test to see if it works fine.
Also re-booted the server a few times, re-compiled, re-checked web.xml and checked the tomcat web logs.
It just simple does NOT work.
package pl;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServerlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>Hello Readers</h1>");
out.println("</body></html>");
}//end of doGet
}//end of Class