• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Glassfish 4.0 with Eclipse Glassfish-web.xml file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic