aspose file tools*
The moose likes Servlets and the fly likes strange problem with my servlet or web.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "strange problem with my servlet or web.xml file" Watch "strange problem with my servlet or web.xml file" New topic
Author

strange problem with my servlet or web.xml file

Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
Hey fellow coders, i'm experiencing a strage problem that I don't quite understand.
I'm still learning J2EE so please bare with me.
I created previous servlets which are in my tomcats directory that run absolutely fine.
Ive stored these servlets in my Tomcat -> "webapps" -> "HelloWorld" -> "classes" -> "com" -> "example"
in this folder I have the following servlets stored in;
HelloWorld.class
ReadCookies.class
SessionTracker.class
UploadServlet.class

i've ran helloworld, readcookies and session tracker many times and i know the work but the problem is the following
with my "web.xml" file

When I try to map the UploadServlet.class to my web.xml (shown below); I keep receiving error "HTTP 404 error; resource not found" for all of my classes;


But when I remove my UploadServlet.class map from the Web.xml (shown below), everything works fine! and i'm able to run the other servlets again Is there something I'm doing wrong



Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10207
    
166

Eric, welcome to CodeRanch.

It looks like your application deployment is failing for some reason. Which server are you using for your web application. The server log file will have the necessary details about why the deployment might be failing. Can you post the relevant contents from that log file?

[My Blog] [JavaRanch Journal]
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
This is the server log file;

Nov 01, 2013 11:28:38 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\IBM\Infoprint Select;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\IBM\Personal Communications\;C:\Program Files (x86)\IBM\Trace Facility\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\13.0\DLLShared\;C:\Program Files (x86)\Lenovo\Access Connections\;;.
Nov 01, 2013 11:28:38 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 01, 2013 11:28:38 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 01, 2013 11:28:38 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 753 ms
Nov 01, 2013 11:28:38 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Nov 01, 2013 11:28:38 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Nov 01, 2013 11:28:38 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\Beer-v1
Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\docs
Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\HelloWorld
Nov 01, 2013 11:28:39 AM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:263)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:142)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 25 more

Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
SEVERE: Error deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\HelloWorld
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\Login
Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\manager
Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT
Nov 01, 2013 11:28:39 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Nov 01, 2013 11:28:39 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Nov 01, 2013 11:28:39 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 800 ms
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1002
    
  13

The problem is here:



It appears that you are missing a jar file.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
J. Kevin Robbins wrote:The problem is here:



It appears that you are missing a jar file.


I added all the external jar files which are commons-fileupload-1.3.jar and commons-io-2.4.jar.

and also how come because i'm missing this jar file, its preventing my other servlet classes from runing, when those servlet are not using any of these jar files?
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
I added those jar files to my class path in eclipse, but i'm wondering if I was suppose to add that jar file to the Tomcat container?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

Of course. Eclipse has nothing to do with really deploying the app. All jars must be contained within the war and be available at run time.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
Oh I see, I'm just now learning J2EE so i guess i'm not used to all this new stuff.

by the way i posted the jar files in my Tomcat -> "lib" where all the jars are and i think it seems to fixed the problem
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

That is a bad idea. Very bad. Hugely bad.

That means that ALL web apps will share those libraries, even if they need conflicting versions.

Jars that are specific to the web app should be in the war file under WEB-INF/lib.

One of the only things you should place in Tomcat's lib folder are JDBC drivers needed for Tomcat-managed connection pooling. Other than that, you should no be putting app-specific jars there.
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
Oh i see, thanks, i'm gonna create a "war" folder under the lib folder and put the jar files there
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Ive stored these servlets in my Tomcat -> "webapps" -> "HelloWorld" -> "classes" -> "com" -> "example"


Oh, I remember that the "classes" folder must be under "WEB-INF", right?


PM Me If You Want to get Urgent Help on Java Programming
Eric Sarpong
Greenhorn

Joined: Nov 01, 2013
Posts: 7
Nam Ha Minh wrote:
Ive stored these servlets in my Tomcat -> "webapps" -> "HelloWorld" -> "classes" -> "com" -> "example"


Oh, I remember that the "classes" folder must be under "WEB-INF", right?


Yes they are there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strange problem with my servlet or web.xml file