I created a simple "hello world" servlet in Eclipse (helios) + Glassfish v3. I am using Glassfish's plugin for eclipse It seems there is no web.xml but a sun-web.xml in the WEB-INF/ folder. This is my first time with glassfish but was a bit surprised at the absence of web.xml - so here are some of the problems:
We have to configure servlet contexts, mappings etc especially during development/testing but the sheer absence of web.xml has me stumped.
Eclipse allows you to not create a web.xml file when you create Dynamic Web Project for Java EE 6, since the Java EE 6 spec (in general) and Servlet 3.0 spec (in particular) attempt to de-emphasize deployment descriptors.
You can use annotation to provide all the data that had been included in the web.xml file. The Javadoc for the Servlet 3.0 annotations is pretty obtuse. You should read through the Servlet 3.0 spec from the jcp.org site to get a bit more explanatory text.
To change the url-mapping for a Servlet 3.0 servlet, the first place to look is in the source code for the servlet. Look for (and change) the value of the urlPatterns element.
If you are trying to create a web app based on Servlet 3.0, try to avoid creating a web.xml file.
The sun-web.xml/glassfish-web.xml file is used to 'finish' the description of a war file for deployment into a GlassFish container.
One other note about the annotations like WebServlet... they do not integrate your annotated class into the class hierarchy, so the correct use of @WebServlet would look like
@WebServlet(
name = "MyServlet",
urlPatterns = {"/path_to_servlet"}
)
public class MyServlet extends HttpServlet {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With