Question

I am trying to teach myself Java, Java EE, and Tomcat pretty much all at once.
(Experienced C/Obj-C dev)

I was following a tutorial at YouTube at: http://www.youtube.com/watch?v=bd50C6XUnFw

I am running:

  • Apache Tomcat/7.0.47
  • JVM 1.7.0_45-b18
  • Mac OS X 10.8.5 x86_64

The error I'm seeing is:

SEVERE: Parse error in application web.xml file at jndi:/localhost/FirstServlet/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/FirstServlet/WEB-INF/web.xml; lineNumber: 8; columnNumber: 19; Error at (8, 19) : Can't convert argument: null
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2719)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1054)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)

As shown in the video the web.xml (at path /Library/Tomcat/webapps/firstservlet/WEB-INF) is:

<web-app>
    <servlet>
        <servlet-name>My FirstServlet</servlet-name>
        <servlet-class>FirstServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <url-pattern>/myfirstservlet</url-pattern>
    </servlet-mapping>
</web-app>

The error indicates that the issue is a null it's hitting after the </servlet-mapping>

So my only assumption is that the tutorial on YouTube is missing something and I must be missing an argument. Suggestions strongly welcomed.

Was it helpful?

Solution

I believe you're missing <servlet-name>...</servlet-name> in <servlet-mapping> section:

<servlet-mapping>
    <servlet-name>My FirstServlet</servlet-name>
    <url-pattern>/myfirstservlet</url-pattern>
</servlet-mapping>

Have a look at basic web.xml file

OTHER TIPS

Between the element servlet-mapping the element servlet-name is missing

<servlet-mapping>
     <servlet-name>MyFirstServlet</servlet-name>
     <url-pattern>/myfirstservlet</url-patter>
</servlet-mapping>

The servlet name is a kind of id which creates a relationship between url and the guven Servlet class.

Suggestions strongly welcomed.

  1. Don't rely on a single tutorial as your sole source of information ...

  2. These things are specified. If you have doubts about the accuracy of a "secondary source" such as a dubious tutorial video, look at the specification.

  3. If reading a specification is too difficult for you1, then look for a reliable tutorial; e.g. for Java-related stuff, look for one written by Oracle.


1 - People who label a specification "obtuse" are probably missing the real point of the specification. A good specification is written with accuracy, precision and completeness as its primary goals. A (so-called) specification that reads like a tutorial is most likely not meeting its primary goals properly.


In this case, the Servlet spec 3.0 (section 14.4.11) makes it clear that you need a servlet-name element to say what Servlet the matching requests are mapped to.

(You could most likely find the same information in other tutorials, etcetera ...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top