I've compiled the source into the class Files, then putted at the folder:
Tomcat 5.5\WEB-INF\ROOT\classes\Files.class
And added this to the web.xml file:
<servlet>
<servlet-name>Files</servlet-name>
<servlet-class>Files</servlet-class>
</servlet>
But when I tried to access the URL http://localhost:8080/Files, I got this error from Tomcat:
Tomcat 5.5 404 Error http://img251.imageshack.us/img251/5042/tomcat404.png
Update: after adding <servlet-mapping> I'm now getting the following error:
exception
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
java.lang.ClassLoader.preDefineClass(Unknown Source)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1960)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:931)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1405)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
This means that the given class definition cannot be found because it has an illegal name /Files. This in turn means that you've changed the <servlet-class> to /Files. This is wrong. You're basically instructing the servletcontainer to declare and instantiate the servlet as follows:
/Files Files = new /Files();
This won't already compile. The complete mapping should look like:
<servlet>
<servlet-name>instanceName</servlet-name>
<servlet-class>com.example.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>instanceName</servlet-name>
<url-pattern>/urlPattern</url-pattern>
</servlet-mapping>
Which is to be interpreted in raw Java code as follows:
com.example.ServletClass instanceName = new com.example.ServletClass();
The <servlet-class> should denote the full qualified classname, including any package. The <servlet-name> should denote the unique instance name. The <url-pattern> should denote the URL pattern for which the servletcontainer should invoke this servlet.
You also need to define a
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
To match the url pattern to the servlet
You also need the servlet-mapping:
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
Also, in you classes folder under WEB-INF, make sure you make a folder whose name is the same as the package name of the classes and put all the classes in that folder. In web.xml, use
<servlet>
<servlet-name>File</servlet-name>
<servlet-class>package.File</servlet-class>
</servlet>
to reference you servlet in the classes folder
Related
I am developing a simple servlet based web application. I am not using any IDE. Following are the steps that i have followed.
Folder Structure :
MyAPP -> Contains WEB-INF folder and index.html
WEB-INF contains 2 folders and web.xml.
Path to loginServlet.java : MyAPP\WEB-INF\classes\servletclass\loginServlet.java
WEB_INF contains lib folder which conatins servlet-api.jar
index.html contains a form and the action attribute of the form contains "login" as value.
MyAPP\WEB-INF\web.xml looks like below :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>servletclass.loginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Compiled the loginServlet.java using command prompt. It created a loginServlet.class file.
Now built a war file using command prompt and deployed it on Tomcat server.
Now when i run the application, it succesfully loads index.html. But as soon as click on Submit button in the form it shows the following error:
java.lang.NoClassDefFoundError: servletclass/loginServlet (wrong name: loginServlet)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2260)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:803)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1244)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:456)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1452)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
Alan is right, do you have the following declaration in your Java file?
package servletclass;
I am using Jersey for my web service, and this is how my web.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-name>com.rohanprabhu.external.interfaces.service.web</param-name>
</init-param>**
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-name>true</param-name>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
</web-app>
I am getting an error Occurred at line 10 column 22, which is where I have marked in my file as '**' (it isn't actually there in the file, I just put it on here). Here is (a part) of the stack trace I get:
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.lang.IllegalArgumentException: Can't convert argument: null
at org.apache.tomcat.util.IntrospectionUtils.convert(IntrospectionUtils.java:889)
at org.apache.tomcat.util.digester.CallMethodRule.end(CallMethodRule.java:476)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1057)
... 188 more
Occurred at line 10 column 22
Marking this application unavailable due to previous error(s)
Here is the entire stacktrace, in case that helps: http://pastebin.com/EX4bMGex
I agree the error message is suboptimal, but I'm also sure you want one <param-name> and one <param-value> per <init-param>. :-)
You are using <param-name> twice. but other init attribute should be <param-value>.
This question already has answers here:
java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted
(7 answers)
Closed 7 years ago.
I am migrating an existing project from Tomcat 6 to 7. Upon startup I am encountering this logged error message:
Jul 02, 2013 2:38:39 PM org.apache.catalina.startup.ContextConfig parseWebXml
SEVERE: Parse error in application web.xml file at jndi:/localhost/padd/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/padd/WEB-INF/web.xml; lineNumber: 309; columnNumber: 21; Error at (309, 21) : The servlets named [ArtefactServlet] and [saveArtefactServlet] are both mapped to the url-pattern [/saveRestoration] which is not permitted
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
...
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: The servlets named [ArtefactServlet] and [saveArtefactServlet] are both mapped to the url-pattern [/saveRestoration] which is not permitted
Here the WEB-INF/web.xml line 309fff:
<servlet-mapping>
<servlet-name>saveArtefactServlet</servlet-name>
<url-pattern>/saveRestoration</url-pattern>
</servlet-mapping>
EDIT:
<servlet-mapping>
<servlet-name>ArtefactServlet</servlet-name>
<url-pattern>/saveRestoration</url-pattern>
</servlet-mapping>
Here tomcat's web.xml:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- The mappings for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
I tried to play around with the mapping, but couldn't make any progress. Hope you can help!
The error says :
The servlets named [ArtefactServlet] and [saveArtefactServlet] are
both mapped to the url-pattern [/saveRestoration] which is not
permitted
So tomcat doesn't know which servlet to be called when your url pattern is matched. Give different url patterns for these two servlets ArtefactServlet, saveArtefactServlet
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!
I'm trying to migrate from Vaadin 6 to Vaadin 7.
When I'm trying to open application url I get a ClassCastException
SEVERE: Allocate exception for servlet Vaadin Application Servlet
java.lang.ClassCastException: com.vaadin.server.VaadinServlet cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I cann't understand what's wrong because it seems that web.xml is ok.
Mapping of application servlet is listed below
<servlet>
<servlet-name>Ohta Application</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>
Vaadin UI class to use</description>
<param-name>UI</param-name>
<param-value>com.ritmsoft.ohta.OhtaUI</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.ritmsoft.ohta.widgetset.OhtaWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Ohta Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Ohta Application</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
Help me, please.
Or if you use Maven make your servlet's scope "provided" like so:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
That way it will use the container's version of the servlet jar if it exists, otherwise it will use the one you declare in Maven.
The problem is most likely caused by javax.servlet.Servlet being loaded by multiple class-loaders. It usually exists in servlet*.jar. It is possible that the container provides its own version of this jar, and your application provides another. Try removing the one in your war.
I have the same issue here, but only if I try to run the vaadin maven project with the tomcat plugin for eclipse. The dependency for the serlet-api is exactly as shown above. Snd tehr eis no difference if I comment it completely or just the scope part.
There is always a servlet-api-2.5-6.1.11 in the lib folder. I don't know from where this comes from. But with the scope provided there is definitly no javax.servlet-api.jar in the lib folder.
And if i copy the war manuelly into the tomcats webapps folder and start if by console it works fine. I don't get the difference.
Any ideas?
Here is what I'm trying to do: we are switching over to using JAXB and Jersey for all our REST services and XML/JSON serialization needs.
So far, I have been able to get a simple test working where some beans are annotated, some test objects created and these are perfectly serialized to either XML or JSON and return to the client upon request. I mostly wrote this based on some of the examples around the Internet, where the an HTTPServer is created and started in the main method.
I am now trying to put this same example into a WAR file and deploy it to my local Tomcat server so I can test it in a more production-like environment. Seeing as I was not able to get it to work on Tomcat 5.5.27 following the instructions here I went ahead and upgraded to Tomcat 6.0. Same instructions, same outcome, a huge InvocationTargetException.
What exactly am I missing guys?
INFO: Scanning for root resource and provider classes in the paths:
/Library/Tomcat/Home/webapps/user/WEB-INF/lib
/Library/Tomcat/Home/webapps/user/WEB-INF/classes
Sep 9, 2009 7:22:32 PM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Root resource classes found:
class example.HelloWorld
Sep 9, 2009 7:22:32 PM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Provider classes found:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.sun.jersey.impl.application.WebApplicationImpl$DefaultComponentProvider.getInstance(WebApplicationImpl.java:437)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:187)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:122)
at com.sun.jersey.impl.application.InjectableProviderFactory.configure(InjectableProviderFactory.java:113)
at com.sun.jersey.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:582)
at com.sun.jersey.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:487)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:622)
at com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:197)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
That's part of the ginormous spew in catalina.out.
Also, here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.impl.container.servlet.ServletAdaptor</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Any help with this would be greatly appreciated! Thanks in advance.
You have probably a conflict somewhere, check your jar files and see if there are no duplicate classes. Use Tattletale to locate the problem
**Caused by: java.lang.NoSuchMethodError: javax.ws.rs.ext.Providers.getContextResolver(Ljava/lang/Class;Ljavax/ws/rs/core/MediaType;)Ljavax/ws/rs/ext/ContextResolver;**
at com.sun.jersey.impl.provider.entity.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:81)
at com.sun.jersey.impl.provider.entity.AbstractRootElementProvider.<init>(AbstractRootElementProvider.java:67)
at com.sun.jersey.impl.provider.entity.XMLRootElementProvider.<init>(XMLRootElementProvider.java:66)
at com.sun.jersey.impl.provider.entity.XMLRootElementProvider$App.<init>(XMLRootElementProvider.java:72)
... 41 more