Servlet JSP does not work

Asked

Viewed 353 times

0

I’m having the following eclipse error while running a Servlet:

HTTP Status 404 - /Testejsp/

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 design structure* Minha estrutura do projeto

Obs I’m using Tomcat 7

  • Good afternoon. Have you set up the right Tomcat?? it appears in the server tab in the eclipse?? if this checks if it has been initialized, generally this error of when it is not initialized

  • @Juliohenrique97 the Tomcat is normally initiating.

1 answer

1


Everything indicates that you need to configure the file called web.xml to open a welcome page when the url http://localhost:8080/Testejsp/ is requested

change your file and put as this example

Example

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

Its error occurs because it does not find index.html

  • see if it works and let me know

  • 1

    Vlw, that’s exactly what I wasn’t trying to say.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.