0

Note: I had start using GlassFish now.

I have Intellij Idea 14.1.1 and Tomcat 8.0.21, I have create a jsp file called index.jsp with and a servlet called TestServlet, i have added the servlet in the web.xml file. The index.jsp file contain a form which action parameter is set to TestServlet and the method is get the form contain only one button. When I run the index.jsp everything is working normal, then when I click the button i get redirected to "http://localhost:8080/TestServlet" and i get HTTP Status 404 - /TestServlet Here is the full content of the page:

HTTP Status 404 - /TestServlet

type Status report

message /TestServlet

description The requested resource is not available.
Apache Tomcat/8.0.21

Here is the code from index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>
  <p>Test works!</p>
  <form action="TestServlet" method="get">
    <button>click me</button>
  </form>
  </body>
</html>

here is the code from the TestServlet

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "TestServlet")
public class TestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("The servlet works!");
    }
}

Here is the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <servlet>
            <servlet-name>TestServlet</servlet-name>
            <servlet-class>TestServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>TestServlet</servlet-name>
            <url-pattern>TestServlet</url-pattern>
        </servlet-mapping>
</web-app>

I hadn't do anything with the TomCat configuration, I only had restarted when I had create the TestServlet and updated the web.xml file. What am I missing?

Planet_Earth
  • 325
  • 1
  • 3
  • 11
  • Isn't TestServlet deployed inside a web application? You should have `/TestServlet` in your form – kolossus Apr 03 '15 at 18:56
  • For some reason tomcat start showing blank pages, and I'm unable to start it. I had switched to glass fish now. I was just going to update the post. Thanks for trying to help – Planet_Earth Apr 03 '15 at 18:57

0 Answers0