Servlet JSP does not work

0

I have the following error in eclipse when running a servlet:

  

HTTP Status 404 - / TestJSP /

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>TesteJSP</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>


  <servlet>
   <servlet-name>Home Servlet</servlet-name>
   <servlet-class>servlet.Home</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>Home Servlet</servlet-name>
    <url-pattern>/home</url-pattern>
  </servlet-mapping>


</web-app>

Servlet

package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Home extends HttpServlet{

    private static final long serialVersionUID = 1L;

    public Home() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doGet(req, resp);
        PrintWriter out = resp.getWriter();
        out.println("<html><head></head><body>Teste</body></html>");
        out.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doPost(req, resp);
    }

}

My project structure *

I'm using tomcat 7

    
asked by anonymous 28.11.2017 / 17:36

1 answer

1

It seems that you need to configure the file called web.xml to open a welcome page when the url url is requested

change your file and place as this example

Example

<welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
</welcome-file-list>

Your error occurs because it does not find index.html

    
28.11.2017 / 17:44