3

I am trying to migrate my existing servlets and filters defined in web.xml file to @WebServlet and @WebFilter annotations on Glassfish V3 server.

Currently web.xml defined 12 servlets and 6 filters . Tried removing one servlet from web.xml file and added @WebServlet annotation to Java servlet file .

But having difficulty in accessing the servlet when ever my JSP trying to access Servlet Glassfish complains "Service Not Available".

basically Servlet and filter defined using annotations never identified by Glassfish Server 3.

Is this existing bug that annotations can not be used along with web.xml file ? Do we have any workaround.

I referred following Sun documentation to migrate web.xml to servlet 3 annotations

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Bheem
  • 31
  • 1
  • 2
  • Like anything in Java, annotations are case sensitive. Thus, it should really have been `@WebServlet` and `@WebFilter`. Although that would have produced completely different and obvious errors, please keep this in mind as well when describing a problem, just to avoid red herrings. – BalusC Jan 19 '10 at 16:58
  • Sorry for the typo BalusC , its @WebFilter and @WebServlet – Bheem Jan 19 '10 at 18:18
  • can you show us the relevant portion of web.xml and the relevant portion of the servlet's java code? – vkraemer Jan 28 '10 at 16:48

1 Answers1

2

You've got to get your web.xml correct, below is the beginning of the web.xml you should use:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    metadata-complete="false" 
    version="3.0" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
ftravers
  • 3,809
  • 3
  • 37
  • 38
  • Thank you, I had a 2.5 version declaration and the @WebServlet annotation was ignored, this answer solved the problem. – stivlo May 11 '11 at 04:09