No web.xml in Eclipse + Glassfish v3?

I created a simple "hello world" servlet in Eclipse (helios) + Glassfish v3. I am using the Glassfish plugin for eclipse. There seems to be no web.xml, but sun-web.xml in the WEB-INF / folder. This is my first time with a glass fish, but was a little surprised at the lack of web.xml - these are some of the problems:

  • Where can I check for url mappings for a servlet? When creating a new servlet in Eclipse, it asks me for the URL mapping, but I can not find it anywhere in any .xml file where I can configure the settings.
  • If there is no web.xml, creating it from scratch will be quite error prone. What do you suggest? Google for sample and play? Shouldn't it be automatically created?
  • Has anyone come across this? I tried to make out the difference between web.xml and sun-web.xml, but the results were not completely enlightening. I would not want to learn another xml for configuration purposes, and this is too specific for glass fish.

We need to configure servlet contexts, mappings, etc., especially during development / testing, but the apparent lack of web.xml puzzled me.

+8
eclipse deployment glassfish deployment-descriptor
source share
5 answers

Eclipse eliminates the need to create a web.xml file when creating a dynamic web project for Java EE 6, because the Java EE 6 specification (in general) and the Servlet 3.0 specification (in particular) try to cancel the underline of deployment descriptors.

You can use the annotation to provide all the data that was included in the web.xml file. Javadoc for Servlet 3.0 annotations is pretty dumb. You should read the Servlet 3.0 description from jcp.org to get a more explanatory text.

To change the url-mapping for the Servlet 3.0 servlet, the first thing to look at is in the servlet source code. Find (and change) the value of the urlPatterns element.

If you are trying to create a web application based on Servlet 3.0, try to avoid creating a web.xml file.

The sun-web.xml / glassfish-web.xml file is used to "complete" the description of the military file for deployment in the GlassFish container.

One more note about annotations like WebServlet ... they do not integrate your annotated class into the class hierarchy, so using @WebServlet correctly will look like

@WebServlet( name = "MyServlet", urlPatterns = {"/path_to_servlet"} ) public class MyServlet extends HttpServlet {} 
+12
source share

If you find that you need a web.xml , you can click the deployment descriptor context descriptor in the Project Explorer view, and there should be an option to “Create deployment descriptor descriptor”. This will create web.xml for you with display-name and welcome-file-list elements.

+10
source share

It seems that when creating a “new” dynamic web project “bad” when you click “Finish”, you should click “next” and go to the last window pane, where you select “generate deployment web.xml" descriptor "- by default it does not set.

Well, that says I'm a little rusty with building web applications. And here I thought it was a problem with glass fish.

+4
source share

Because Glassfish 3.x is a fully certified Java EE 6 server, it supports Servlets 3.0. Starting with Servlets 3.0, you can specify web.xml parameters through annotations.

for example

 @WebServlet( name = "MyServlet", urlPatterns = {"/path_to_servlet"} ) public class MyServlet {} 
+3
source share

To add to what TMN said, I noticed that the project explorer would not show the deployment descriptor until I did an SVN update for some reason. If you have this problem, try updating the code. I was already in the editorial office of HEAD, but for some reason the update showed this view.

0
source share

All Articles