I am attempting to learn about web development by learning about servlets and JSP. To that end, I have downloaded and installed a Java JDK 1.7, Eclipse Kepler,
and Glassfish 4.0. I have added the glassfish server to Eclipse and all of that went well. I have written a small servlet in order to test the server, following the
instructions in the book that I am trying to learn from (Head First Servlets and JSP).
I am running into an issue when I try to add statements to the glassfish-web.xml file. The book uses Tomcat as a web server, and the commands that I type in give me
errors. I do not have the experience to determine what these errors are trying to tell me. Following is the code from the glassfish-web.xml file:
I receive errors on the <glassfish-web-app> tag and the <servlet> tag. The errors on the <glassfish-web-app> tag are as follows:
Multiple annotations found at this line:
- Attribute "xsi:schemaLocation" must be declared for element type "glassfish-web-app".
- Attribute "xmlns" must be declared for element type "glassfish-web-app".
- Attribute "version" must be declared for element type "glassfish-web-app".
- Attribute "xmlns:xsi" must be declared for element type "glassfish-web-app".
- The content of element type "glassfish-web-app" must match "(context-root?,security-role-
The error on the <servlet> tag are as follows:
The content of element type "servlet" must match "(servlet-name,principal-name?,webservice-endpoint*)".
Any insight into these issues would be appreciated.
This is something you probably merge what apparently commonly appeared in web.xml into the glassfish-web.xml. This manoeuvre is incorrect and unnecessary.
[1.1] What it entails is making glassfish-web-app tag to live in ...j2ee namespace (now a default namespace) which it is not.
[1.2] There is a consequential typo: XMLSchema-instance, not XMSSchema-instance which will confuse validator like hell.
[1.3] Another material typo is in the xsi:schemaLocation, j2ee not h2ee. Again it makes only confusion to the validator if ever it is called upon to validate.
[1.4] The action to take is to eliminate them all leaving it look like this.
Now the glassfish-web-app element will be validated against the dtd specified in the DOCTYPE line(s).
These make sense because the glassfish-web-app element was validated against the dtd resolved against the DOCTYPE (http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd). If you download a copy of the dtd and read its content, you will see why the validator was complaining about.
This is a message derived from the dtd, if you read it. Now, do you see sevlet-mapping appeared in the list that 'the content of element type "glassfish-web-app" must match" ? No, it isn't there. What it means is that
should have no place in the glassfish-web.xml. Consequently, take the whole thing out of it.
 This is the part concerning the servlet element appeared in the dtd.
<!ELEMENT servlet (servlet-name, principal-name?, webservice-endpoint*)>
You cannot even have servlet-class element as a child to servlet element for glassfish-web.xml. You have it there just because you move something proper to web.xml to glassfish-web.xml. That is not the correct way of constructing glassfish-web.xml. So I would say, take the whole servlet tag out completely as well. I don't think you need it there.
 What left is that you can test using the descriptor leaving the context-root element there inside the glassfish-web-app element.
Should I be concerned that there is no web.xml file under the WEB-INF folder? Also, once I eliminate everything in the glassfish-web.xml file, and try to run my servlet on the server, I constantly get a 404, and the path URL path that is built contains an folder that is not part of the project that I created. The URL that is generated is http://localhost:8080/HeadFirstServletJSP/servlet/test.Ch1Servlet. The "servlet" folder is nowhere in my project.
First you should check what the book says, should you not?
Should I be concerned that there is no web.xml file under the WEB-INF folder?
Most of the time, if you're using Servlet 2.x, you should.
Also, once I eliminate everything in the glassfish-web.xml file, and try to run my servlet on the server, I constantly get a 404, and the path URL path that is built contains an folder that is not part of the project that I created.
I would say that you reposition those lines, servlet and servlet-mapping back to the web.xml in your application war. That was what I meant too.