File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Glassfish and the fly likes Glassfish 4.0 with Eclipse Glassfish-web.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Glassfish
Bookmark "Glassfish 4.0 with Eclipse Glassfish-web.xml file" Watch "Glassfish 4.0 with Eclipse Glassfish-web.xml file" New topic
Forums: Glassfish Servlets XML and Related Technologies
Author

Glassfish 4.0 with Eclipse Glassfish-web.xml file

David Bretz
Greenhorn

Joined: Sep 03, 2003
Posts: 2
I apologize if this question is too elementary, but I am new to the web development arena and I am stuck.

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-
mapping*,servlet*,idempotent-url-pattern*,session-config?,ejb-ref*,resource-ref*,resource-env-ref*,service-
ref*,message-destination-ref*,cache?,class-loader?,jsp-config?,locale-charset-info?,parameter-
encoding?,property*,valve*,message-destination*,webservice-description*,keep-state?,version-identifier?)".

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.

Thanks.

DB
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
[1]

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).

[2]

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.

[3]

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.

[4] This is the part concerning the servlet element appeared in the dtd.
glassfish-web-app_3_0-1.dtd wrote:
<!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.

[5] What left is that you can test using the descriptor leaving the context-root element there inside the glassfish-web-app element.
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 335
    
    7

I can't help with all the issues that you mention, but I did notice that the servlet name didn't match in your descriptor - that will be a problem later.

<servlet>
<servlet-name>
Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>
Chpter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
David Bretz
Greenhorn

Joined: Sep 03, 2003
Posts: 2
Thanks for the responses.

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.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
I would much prefer to let servlet people to answer... upon waiting I try to answer your following up concerns.

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Glassfish 4.0 with Eclipse Glassfish-web.xml file