Hello, there is an example from the book Head first Servlets and JSP, which cannot be started.

web.xml (Path: webapps \ ch1 \ WEB-INF)

<?xml version=”1.0” encoding=”ISO-8859-1”?> <web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=”2.4”> <servlet> <servlet-name>Chapter1Servlet</servlet-name> <servlet-class>Ch1Servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Chapter1Servlet</servlet-name> <url-pattern>/Serv1</url-pattern> </servlet-mapping> </web-app> 

Ch1Servlet.class (Path: webapps \ ch1 \ WEB-INF \ classes)

 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>"); } } 

Browser URL: http: // localhost: 8080 / ch1 / Serv1

No connection to the site Host localhost rejected the connection request. ERR_CONNECTION_REFUSED

Tomcat runs fine, standard examples too. What is the trouble?

  • I apologize, at the address localhost: 8080 tomcat is launched, but HelloWorld does not display standard, the same message pops up in the browser - Igor Gorbunov
  • Path: webapps \ ch1 \ WEB-INF \ classes. This path must be in the Tomcat folder. Do you have it? - Vladimir Glinskikh
  • ERR_CONNECTION_REFUSED is usually a network error. Most likely, the request does not even reach the application server. Or this service is not even running. If the server is working, then in the worst case I would write an HTTP protocol error: the resource was not found, an internal server error, etc. - Sergey
  • @Vladimir, this path is in the folder. Tomcat set up fine, now climbs 404 (What am I doing wrong? - Igor Gorbunov
  • one
    @Vladimir, thanks for the answer, the book was an outdated example. For my part, I did everything right. I found the answer when I started typing web.xml in IntelliJ IDEA - she suggested the right way - Igor Gorbunov

0