FAIL - Application at context path /Hello could not be started - deployment

I'm trying to deploy new web application in Tomcat 6.0, but whenever I click on start button, I repeatedly getting FAIL - Application at context path /Hello could not be started. Other deployed application running fine, whenever I click on start button. But why not this application?
web-xml:
<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">
<servlet>
<servlet-name>j_security_check</servlet-name>
<servlet-class>EmailHander</servlet-class>
</servlet>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/fail_login.html</form-error-page>
</form-login-config>
</login-config>
<web-app>
This is what Exception I'm getting in catalina log file:
Jan 23, 2010 6:49:31 PM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/Hello/WEB-INF/web.xml
org.xml.sax.SAXParseException: XML document structures must start and end within the same entity.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1644)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1066)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4339)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1249)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:612)
at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
What is the reason of that error in web-xml file?

Your web.xml ends with <web-app>, but must end with </web-app>
Which by the way is almost literally what the exception tells you.

You need to close the XML with </web-app>, not with <web-app>.

Is EmailHandler really the full name of your servlet class, i.e. it's not in a package like com.something.EmailHandler? It has to be fully-qualified in web.xml.

I've had the same problem, was missing a slash in servlet url in web.xml
replace
<servlet-mapping>
<servlet-name>jsonservice</servlet-name>
<url-pattern>jsonservice</url-pattern>
</servlet-mapping>
with
<servlet-mapping>
<servlet-name>jsonservice</servlet-name>
<url-pattern>/jsonservice</url-pattern>
</servlet-mapping>

check web.xml file maybe servletContextlistener not doing well .
in my case i added servletContextlistener and let him an empty and gave me the same error, i tried to delete it from project files but it still in web.xml file .finally i delete it from the web.xml and save the file . run the project and it stated successfully

1st Reason could be the ending tag of your application's web.xml file which could not have been closed properly.
web.xml might be ending with <web-app>, but must end with </web-app>
2nd Reason which worked in my case could be the lib folder of your tomcat must contain the supporting jar file of your database.
ojdbc on case of Oracle or sqljdbc in case of SqlServer

Related

Struts 2 Hello World

I have a problem at this example
I work with eclipse for Java EE and Apache Tomcat 8.
My project structure:
The web.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">
<display-name>Hello World Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The other files code is the same as the struts website.
When I run the index.jsp file I get the following error:
**HTTP Status 404 - /helloworld/index.jsp
type Status report
message /helloworld/index.jsp
description The requested resource is not available.**
Can someone spot the reason why can't I run it?
First of all the project is created by using Maven configuration, and to access the Struts action you should use url
Step 6 - Build the WAR File and Run The Application
Execute mvn clean package to create the war file.
Copy the war file to your Servlet container. After your Servlet
container successfully deploys the war file go to this URL
http://localhost:8080/helloworld/index.action where you should see
the following:
(source: apache.org)
Web application context is where the application was deployed. In the docs url it's /helloworld, on the image it's /Hello_World_Struts2_Ant. Use it as a part of the url. It doesn't matter which app context did you use during deployment but url depends on it. If you want to change the web app context you should read Java - How to change context root of a dynamic web project in Eclipse. After the context you use action name with .action extension to execute action.
Don't use URLs like localhost:8080/helloworld/index.jsp because you might not get the resource because it's already handled by the web server.

java.lang.IllegalArgumentException: Invalid <url-pattern> coreservlets.ShowItems_ArrayList

Eclipse Version: Kepler Service Release 1
Build id: 20130919-0819
Steps taken so far:
(1) Deleted the .snap file located in the directory
<workspace-directory>\.metadata\.plugins\org.eclipse.core.resources
(2) Deleted tmp folder in the following directory
<workspace-directory>\.metadata\.plugins\org.eclipse.wst.server.core
(3) Clean project & server
(4) Reconfigured the server by deleting the current server, & adding
new server
(5) Just to ensure changes to reflect, restarted Eclipse every time
after performing above steps.
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> coreservlets.ShowItems_ArrayList in servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3279)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3254)
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1430)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1344)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
However, all the tips & tricks seems to have gone in vain.
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>ShowItems_ArrayList</servlet-name>
<servlet-class>coreservlets.ShowItems_ArrayList</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShowItems_ArrayList</servlet-name>
<url-pattern>coreservlets.ShowItems_ArrayList</url-pattern>
</servlet-mapping>
</web-app>
Your url-pattern is not in the correct format. It needs to start with a slash. While not an exact duplicate, see this question:
Why should url-pattern in servlet mapping start with forward slash(/)

Welcome file list issue in Jetty, works fine with Jboss

Issue I'm facing is as follows.
In Jboss I have web.xml as follows...
<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>com.exp.ServletExample</servlet-class>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/test/hello</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>NewFile.html</welcome-file>
</welcome-file-list>
</servlet>
And when I try _http://localhost:8800/SimpleServletProject/ - [SimpleServletProject is the war file name] then my welcome file i.e. NewFile.html is getting displayed.
If I put the same war on jetty and type _http://localhost:8080/SimpleServletProject/ it doesn't work... I get 404 error saying
HTTP ERROR 404
Problem accessing /SimpleServletProject/index.jsp. Reason: not found
My war structure is as follows
SimpleServletProject.war
-META-INF
-WEB-INF
-NewFile.html
I'm struggling with this issue, any help would be much appreciated.

java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted

I tried to add this servlet
package com.classmgt.servlet;
#WebServlet("/ControllerServlet")
public class ControllerServlet extends HttpServlet {}
to my Eclipse project, by editing the web.xml as below
<servlet>
<description>Servlet to print out Hello World!</description>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.classmgt.servlet.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
However, I got the following exception:
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ClassManagementSystem]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ClassManagementSystem]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 7 more
Caused by: java.lang.IllegalArgumentException: The servlets named [ControllerServlet] and [com.classmgt.servlet.ControllerServlet] are both mapped to the url-pattern [/ControllerServlet] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2457)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2139)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2100)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1300)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
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:5269)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
I have tried adding metadata-complete="true" to web.xml, but it does not recognize the servlet anymore.
Caused by: java.lang.IllegalArgumentException: The servlets named
[ControllerServlet] and [com.classmgt.servlet.ControllerServlet] are
both mapped to the url-pattern [/ControllerServlet] which is not
permitted
It seems that you have mixed #WebServlet annotation based and web.xml based configuration.
I doubt that you created a Servlet using the "Create Servlet" wizard which creates web.xml entry with url-pattern and then , added a #WebServlet annotation which duplicates anything you may put in the web.xml.
You should use the one or the other, not both. Remove the mapping from web.xml and go ahead with using only the #WebServlet annotation.
Read more: Servlet 3.0 Annotations and our Servlets wiki page.
Just remove the annotation #WebServlet("/ControllerServlet"), from the ControllerServlet, because it already added in the web.xml.
java.lang.IllegalArgumentException: The servlets named...
I fetched this cause where I create new servlet in different package (name='syncro'). My servlet located in syncro.SynchronizeServlet
And when I add information about this servlet in deployment descriptor (web.xml) I catch error: IllegalArgumentException
Example of incorrect descriptor part:
<servlet>
<description></description>
<display-name>SynchronizeServlet</display-name>
<servlet-name>SynchronizeServlet</servlet-name>
<servlet-class>SynchronizeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SynchronizeServlet</servlet-name>
<url-pattern>/SynchronizeServlet</url-pattern>
<url-pattern>/SynServlet</url-pattern>
</servlet-mapping>
When I add correct path for servlet - error disappeared. Correct desc below:
<servlet>
<description></description>
<display-name>syncro.SynchronizeServlet</display-name>
<servlet-name>syncro.SynchronizeServlet</servlet-name>
<servlet-class>syncro.SynchronizeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>syncro.SynchronizeServlet</servlet-name>
<url-pattern>/SynchronizeServlet</url-pattern>
<url-pattern>/SynServlet</url-pattern>
</servlet-mapping>
==> 73!
What worked for me is doing a 'clean'.
My issue was caused when the Servlet class was renamed. However, the original .class files remained in the target directory (with their Servlet annotation). It looks like you moved your ControllerServlet into a package.
Jetty didn't seem to mind these apparent duplicates, but Tomcat7 gave your
'both mapped to the url-pattern' exception.
The easy way to see if this is causing your issue is to look in the WAR to see if both the old classes (in your case [ControllerServlet] and [com.classmgt.servlet.ControllerServlet]) are both there.
As for me I added the tom-cat version to my pom file and it worked
<properties>
<tomcat.version>7.0.52</tomcat.version>
</properties>
<dependencies>
The servlets named [Register] and [com.TeamWork.controller.Register]
are both mapped to the url-pattern [/Register] which is not permitted
getting this error you have to remove your servlet mapping from web.xml and just add #WebServlet("/Register") annotation + url
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>com.TeamWork.controller</servlet-class>
</servlet>
then your servlet class on the top add this one
#WebServlet("/Register")`
public class Register extends HttpServlet { }
it will work thanks
For me, it was an unexpected error in Intellij Idea.
I deleted a servlet 2 days back which was having the same URL pattern. However, I am getting the error that my new servlet and that deleted one have the same URL pattern. This was strange.
Tried cleaning the Tomcat v10.0.23 server,
Restarted the server,
Build the exploded artifact,
Restarted IDE.
Nothing works!!
Finally, I run the project in debug mode and that fix my issue.
This is strange but maybe I did something wrong that's why I faced this issue.
Hope this can help someone if they're facing the same issue.

Problems in creating JSF project in eclipse [duplicate]

I'm using this :
Tomcat 7.0
JSF 2.0
JRE 7
but when trying to run my application, I got the following exception:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1011)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:159)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getELContext(FacesContextImplBase.java:210)
at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1463)
at org.apache.myfaces.webapp.AbstractFacesInitializer._createFacesContext(AbstractFacesInitializer.java:477)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initStartupFacesContext(AbstractFacesInitializer.java:449)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:113)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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)
Any ideas why?
Thanks,
That may happen if your webapp's runtime classpath is polluted with multiple JSF impls/versions. The org.apache.myfaces entries in the stack trace tells that you're using MyFaces. This problem thus suggests that you've another JSF implementation like Mojarra in the webapp's runtime classpath which is conflicting with it. It's recognizable by jsf-api.jar, or jsf-impl.jar, or javax.faces.jar. If you remove all of them, then this problem should disappear.
Or, if you actually intented to use Mojarra instead of MyFaces (you did namely not explicitly state the intented JSF impl/version anywhere in your question, but you just generically stated the JSF spec as in "JSF 2.0", so perhaps you actually had no clue what you was all doing), then you should be removing myfaces-*.jar files from your webapp.
See also:
JSF wiki page - Installing JSF
How to properly install and configure JSF libraries via Maven?
Difference between Mojarra and MyFaces
JSF implementations and component libraries
Complementing BalusC's answer, I recently got this error when trying to run an independent JAR with a Spring Boot application that has JSF as front-end with Spring-managed beans. Switching the packaging from JAR to WAR solved the problem.
For me {Tomcat 8, JSF 2.2, JRE 8}, the following steps worked:
Download JSTL jars API && IMPL and place it in your Tomcat lib.
Since downloading Majorra directly from eclipse in project
facets configuration is recently impossible ; "Zip File is empty Exception",
manually download jsf-api.jar and jsf-impl.jar and include them in a
new user library added to build path(only once!).
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>TestJSF</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
In addition to what's already said, I faced this issue when importing a third party project, the reason was that two profiles were defined in the pom.xml, one for My Faces and another for Mojarra.
If this is your case, you just need to select one of them with maven -P or in Project properties, Maven section, indicating the profile(s) to be used.
In my case this exception was caused on webapp shutdown by the presence of com.sun.faces.config.ConfigureListener in web.xml, running Mojarra 2.2.x under Tomcat 8.0. As described in this answer, this causes Tomcat to register that listener twice (both automatically and by virtue of the web.xml entry) and hence, among other things, its contextDestroyed method is executed twice, the second time producing the described exception (most probably because JSF was already shut down by the first listener registration).
I had no classpath conflict in my case: just one version of Mojarra (2.2.6) and no MyFaces.