I am attaching a war file that prints hello using servlet

This is code for web.xm

<?xml version="1.0" ?>
- <web-app>
- <servlet>
<servlet-name>hello</servlet-name>

<servlet-class>servlet1</servlet-class>

</servlet>


- <servlet-mapping>
<servlet-name>hello</servlet-name>

<url-pattern>/hello</url-pattern>

</servlet-mapping>


</web-app>

but its throiwng some exception

WHAT exception?
And where?

And no, we're not going to download and execute some code you attach here or anywhere else.
Such tricks are far too often used by people trying to spread virusses.
Plus it's not our task to figure out what problems you're having, that's your job.
When you do figure it out, tell us in detail and we might be able to help you find an answer.

Hi Jweting

Thanks for your wonderful reply , i do agree that ppl may spread virus like this.

The code i have written is absolutely correct , i think web.xml you have already seen.

I have got some clue why this problem is occurring , let me narrow down that .If what i am thinking comes true then i will report a bug in Apache itself.

Thanks

And plpease please dont be so rude

You should atleast have pasted the 'stack trace' for us to help you out. The code as such looks OK. Paste the stack trace and the way you are trying to execute the WAR file.

if your code were "absolutely correct" you'd not be getting any errors.
Therefore one can only conclude that that code is NOT in fact correct.

hi.............I pasted War file in Web-apps and called it from browser

this is error stack

Yes i added web.Xml File with follwoing code

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" >
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

</web-app>

and it is throwing

Aug 8, 2007 12:31:07 PM org.apache.catalina.startup.ContextConfig applicationConfig
SEVERE: Parse error in application web.xml
java.lang.IllegalArgumentException: Invalid <url-pattern> null in servlet mapping
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1548)
at org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:302)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:644)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:254)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4212)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:850)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:316)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:859)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:653)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1067)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:371)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
at org.apache.catalina.core.StandardHost.backgroundProcess(StandardHost.java:827)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1659)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1668)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1648)
at java.lang.Thread.run(Unknown Source)
Aug 8, 2007 12:31:07 PM org.apache.catalina.startup.ContextConfig applicationConfig
SEVERE: Occurred at line 10 column 19
Aug 8, 2007 12:31:07 PM org.apache.catalina.startup.ContextConfig start

You still haven't told us your Tomcat version..

But still, try out this xml file format:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
<web-app>
    <display-name>Hello, World Application</display-name>
    <description>
    This is a simple web application with a source code organization
    based on the recommendations of the Application Developer's Guide.
    </description>

    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>servlet1</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/goHello</url-pattern>
    </servlet-mapping>

</web-app>

And run it using: http://localhost:8080/your_root_dir_name/goHello

Tomcat 5.5.4

Have you tried simply removing the "-" characters from those three lines? Some XML Parsers (possibly Tomcat's included) are a little picky.

Have you tried simply removing the "-" characters from those three lines? Some XML Parsers (possibly Tomcat's included) are a little picky.

Methinks he directly copy pasted from the XML opened in IE and hence those dashes.

Staneja, did the XML file provided by me not work? I have seen a lot of bug reports lying around here and there regarding the same problem. The same XML file works fine for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.