1

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 Report

Message /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
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
nanren
  • 13
  • 1
  • 3
  • Did you release use backslashes in your URL? "localhost:8080\First\hello". Try it with normal slashes: "localhost:8080/First/hello" – vanje Jan 07 '19 at 20:50
  • Good morning, vanje: I tried the backslash "\" in the URL, but it will be automatically changed to normal slash "/" in Chrome. It works fine new once I changed the WEB_INFO back to WEB-INF. Thanks very much and have a nice day. – nanren Jan 09 '19 at 13:47

1 Answers1

2

You have a typo in your web application directory structure. It should be WEB-INF not WEB-INFO.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
  • 2
    Dear Mark Thomas, You answered my question and saved me a big headache . I worked on this issue for few weeks until I post it here. Thanks so much and have a great day. – nanren Jan 09 '19 at 13:29
  • I also appricated whoever edited my original post and put the java code and web.xml into it to make it clean and readable. Apologize for my lack of the skill to post it correct in the first place. Many thanks and have a nice day. – nanren Jan 09 '19 at 13:39