2

i am developing an example servlet on tomcat 7.0.37 & eclipse 3.7. My current problem is to get it runnable :(

//...imports and so on...

@WebServlet(value="/Hello")
public class AdminServlet extends HttpServlet
{
    private static final long serialVersionUID = -1139419481702036147L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        super.doGet(req, resp);

        PrintWriter writer = resp.getWriter();
        writer.write("HelloWorld");
        writer.close();
    }
}

When I call the URL "http://localhost:8080/{webappname}/Hello" a window turned to "Status 404 - Resource not available". Is there anything wrong?

It is like in the most Servlet 3.0 examples :(

Roman C
  • 48,723
  • 33
  • 63
  • 158
George Krause
  • 59
  • 3
  • 11

4 Answers4

1

Below are some of the causes:

  • Make sure your Servlet container supports Servlet 3.0. Most of them should support the,
  • Make sure your web.xml has version 3.0. For web.xml version < 3.0, the annotations may not get processed.
  • Make sure metadata-complete attribute is false. If it is true, the annotation may not get processed.
Ramesh PVK
  • 15,050
  • 2
  • 44
  • 49
0

Create {webappname}.war, put it in the webapps dir and restart the server.

Roman C
  • 48,723
  • 33
  • 63
  • 158
0

The problem is you are not mapping the servlet to the correct url pattern. The servlet name should be mapped to the URl pattern. But in your code it's not done.

To do it correctly using annotations please see the following.

@WebServlet( name="AdminServlet", displayName="Admin Servlet", urlPatterns ={"/Hello","*.do"})
public class AdminServlet
karthick
  • 11,550
  • 5
  • 52
  • 83
0

I found my issue: I had to remove "super().doGet();"

George Krause
  • 59
  • 3
  • 11