0

I have just picked up web development and I cannot for the life of me figure out what I'm doing wrong when mapping the SimpleServlet in web.xml

these are my files:

Proyect Files

My web.xml is:

<?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"
    version="3.0">
    <display-name>JavaHelloWorldApp</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>SimpleServlet</servlet-name>
        <servlet-class>wasdev.sample.servlet.SimpleServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SimpleServlet</servlet-name>
        <url-pattern>/SimpleServlet</url-pattern>
    </servlet-mapping>
</web-app>

Simple Servlet

package wasdev.sample.servlet;

import java.io.IOException;

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

/**
 * Servlet implementation class SimpleServlet
 */
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.getWriter().print("Hello World!");
    }

}

I am simply trying to get a local host running and access the JavaHelloWorldApp/SimpleServlet

Cœur
  • 37,241
  • 25
  • 195
  • 267
vega2015
  • 119
  • 3
  • 11
  • What error are you getting? – DanielBarbarian Apr 20 '17 at 14:47
  • @DanielBarbarian 404 – vega2015 Apr 20 '17 at 15:39
  • I assume your web application context root is JavaHelloWorldApp? Do you have any error messages when your application is starting up? – DanielBarbarian Apr 20 '17 at 15:51
  • @DanielBarbarian I don't get any errors, after some time of googling and looking around I added the exact folder to my web deployment assembly and it seemed to work, however now after I modify my servlet and build the project my changes don't seem to be taking any effect on my local host – vega2015 Apr 21 '17 at 13:54
  • Ok, one thing that I noticed is that you have added a servlet mapping definition in your web.xml and in your servlet class, both pointing to the same path. I know that this may cause issues as containers may consider this to be two separate configurations and as they are for the same path, they collide. I would suggest one or the other but not both. – DanielBarbarian Apr 24 '17 at 07:21

0 Answers0