Requested Resource (servlet name) not found Tomcat Eclipse IDE - eclipse

I am trying to deploy a servlet on Tomcat from Eclipse using WTP plugin. Eclipse is working fine and Tomcat is also up. As when I open http://localhost:8080 I get the home page of Tomcat. I am following this exact tutorial http://www.vogella.com/articles/EclipseWTP/article.html but when I try to deploy it on tomcat by right clicking on servlet class and run as run on server I get following error. The requested resource (/test/FileCounter) is not available. I searched but could not find anything which could help me. I am using Eclipse Java EE IDE and Tomcat 6. Following is my 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<servlet>
<description></description>
<display-name>FileCounter</display-name>
<servlet-name>FileCounter</servlet-name>
<servlet-class>com.servlets.FileCounter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileCounter</servlet-name>
<url-pattern>/FileCounter</url-pattern>
</servlet-mapping>
</web-app>

I faced this same problem and just solved it !
In the Project Explorer , expand the Deployment descriptor ( just above the Java resource ) . Then expand "servlet" in that deployment descriptor , their should be your created Servlet. Right click on it and Run as --> Run on server .
But one thing isn't clear to me in Eclipse that web.xml is not defined properly but the servlet is running without it !

I just had this same problem. It appears from some reason when I created the servlet through the servlet wizard, eclipse did not create a web.xml file in the WebContent WEB-INF folder. I don't know why it didn't create it.
I added the web.xml file into the WebContent/WEB-INF folder and when I did that, I had a servlet under deployment descriptor that I could right click on and run as -> run on server
Here is the web.xml file you need:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<servlet>
<description></description>
<display-name>FileCounter</display-name>
<servlet-name>FileCounter</servlet-name>
<servlet-class>your.servlet.path.filecounter.servlets.FileCounter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileCounter</servlet-name>
<url-pattern>/FileCounter</url-pattern>
</servlet-mapping>
</web-app>
Of course you will want to update your servlet class to the package name you created

Related

Error in web.xml while creating a dynamic web project in eclipse

I am trying to create a new web project using eclipse
File-> new -> Dynamic web project
Next Next and Finish
Here I get the web.xml and it shows me the following error
(if I select 2.5 dynamic web module version):
cvc-elt.1.a: Cannot find the declaration of element 'web-app'.
(if I select 3.0 dynamic web module version):
Error while downloading 'http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd' to C:
\Users\yg178f\.lsp4xml\cache\http\java.sun.com\xml\ns\javaee\web-app_3_0.xsd.
Here is my web.xml
<?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>Struts2Demo</display-name>
<welcome-file-list>
<welcome-file>index.html</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>
</web-app>
I took this web.xml from here, and got rid of the issues, by removing all the URLs:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Environment variables path image
I had the same problem. I just uninstalled jdk along with the eclipse enterprise IDE. Downloaded jdk version 11 and installed it. Went to the environment and created a new file under JAVA_HOME and linked it to the jdk version 11. Added this to my path along with the CATALIN_HOME linked to tomcat version 9.
I then installed Eclipse enterprise ide for java developers(eclipse jee 2018-12-R) and created a new project. Voila!
The only downside is that they're a bit outdated, but hey better that than the hassle of an xml error.
Anyways if anyone's got a better solution, I am all in.

Eclipse we-app Error using google cloud

Eclipse is returning a couple of quite frustrating errors.
attribute xmlns must be declared for element type web-app
attribute version must be declared for element type web-app
This is the source code for web.xml
I got it from following the instructions from this site.
https://cloud.google.com/appengine/docs/java/gettingstarted/ui_and_code
Here is also the code...
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>guestbook</servlet-name>
<servlet-class>com.example.guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>guestbook.jsp</welcome-file>
</welcome-file-list>
</web-app>
The errors occur on line 5. I'm not sure s to how to fix this problem. Any input would be greatly appreciated.
You can replace the first 5 lines with this:
<?xml version="1.0" ?>
<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">
But your app will probably run properly anyway, so you can also disable that Eclipse warning.

HTTP Status 404 The requested resource is not available jersey tomcat

I am having trouble to launch my testing app on the tomcat8 server. When i enter the http://localhost:8080/loginService/rest/auth, the error message is "HTTP Status 404 -
type Status report. message: description The requested resource is not available."
And the starting page http://localhost:8080/ works fine.
I put all the jar files(jersey-client, jersey-common, jersey-container-servlet,jersey-container-servlet-core, jersey-server, javax.ws.rs-api-2.0 ....) under the WEB-INF/lib. And loginService is deployed by the server.
the web.xml file under WEB-INF
<?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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>loginService</display-name>
<servlet>
<servlet-name>Jersey REST Service</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-value>loginTest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
my testing app:
package loginTest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/auth")
public class Authenticate {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String test() {
return "succes";
}
}
Here are the part of the console msg which seems like a problem:
七月 10, 2014 3:06:20 下午 org.apache.catalina.core.StandardContext reload
严重: Exception starting Context with name [/loginService]
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/loginService]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3780)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:293)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5539)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1365)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1369)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1345)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/base/Function
at org.glassfish.jersey.internal.ServiceFinder.<clinit>(ServiceFinder.java:165)
at org.glassfish.jersey.servlet.internal.ServletContainerProviderFactory.getAllServletContainerProviders(ServletContainerProviderFactory.java:66)
at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:132)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 8 more
Caused by: java.lang.ClassNotFoundException: jersey.repackaged.com.google.common.base.Function
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
... 13 more
七月 10, 2014 3:06:20 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/loginService] is completed
And I am using tomcat8 and jersey2.10.1.
I just changed my web.xml file to :
<?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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>loginService</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>loginTest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
It seems like your application is missing some of the required libraries or (Since you already have the jercy-common.jar) there is an incompatibility in the libraries already in the classpath.
Therefore I would like to point out a perfectly working(Tested with Tomcat 8) sample in the below link.
Jersey-HelloWorld-Example
Hope this helps.
I had this problem. I just solved it by deleting all web.xml files (inside "target" folder and "main" folder). Then right click on the project in Project Explorer and java EE tools -> Generate Deployment Descriptor Stub. After that just right click again on the project -> run as -> Maven build... Then in "Goals" field write: "clean install" (whithout quotes). Click on Apply, click on Run. Then go to your Tomcat manager, undeploy the old .war file and deploy it again. Then just run it! It worked for me.
According to this link https://www3.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html#TomcatDebug , there are many reasons for this kind of problem to occur. In addition, I had been through this problem before. I solved it through the following way. Take a look at the web.xml heading in tomcat/webapps/ROOT/WEB-INF/web.xml. And make sure your your web.xml looks like that. Specially try to compare the versions. For instance:
Mine was:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
........
..........
</web-app>
The tomcat version that you install can be like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="4.0"
metadata-complete="true"
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_4_0.xsd">
........
..........
</web-app>
If you look at both they have version difference and metadata attribute difference. So header of both your web.xml and tomcat/webapps/ROOT/WEB-INF/web.xml must be identical. By changing version number within the header of my web.xml into 4 solved my problem. Whatever version you have, make sure it is identical with the ROOT's web.xml version. Hope it helps

Tomcat7 giving HTTP 404 ERROR while running the jsp file

I am having 404 error in the maven web-app project. I am using tomcat in the port 8081,
The web.xml is as below;
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<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">
<display-name>testProject</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Do anybody have any Idea what might be wrong with the projects. I have other projects in my eclipse and they work. Also I tried to use jBoss but the error is same. I thing some kind of configuration is left out and I could not figure what.
Thank You in advance.
In your ScreenShot the red X on the project mean that eclipse found some error in your project. Often eclipse will not compile or deploy as long as there exist a serious error.
So fix the problem first, and then retry.
Beside what Ralph suggested to check any possible build errors, you may also try moving your JSP page to src/main/webapp directory, and then in the project setting make sure that the web deployment assembly has the correct mapping. As an example, your src/main/webapp directory should be mapped to web context root / as shown the following example setting

Unable to compile servlet in jetty

I have a google app engine connected project (in eclipse juno) and it contains a simple servlet file but for some reason when I run the project ,the corresponding class file is not getting created inside WEB-INF/classes folder, in fact there is no classes folder inside WEB-INF. and hence I am unable to run the servlet.I will appreciate if someone could suggest some solution.
Below is my web.xml file->
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.queryname.DeviceInfoEndpoint,com.queryname.MessageEndpoint</param-value>
</init-param>
<servlet-name>QueryServiceServlet</servlet-name>
<servlet-class>com.queryname.QueryTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>QueryServiceServlet</servlet-name>
<url-pattern>/Query/*</url-pattern>
</servlet-mapping>
</web-app>
I get the following exception-->
WARNING: Failed startup of context com.google.appengine.tools.development.DevAppEngineWebAppContext#684528a3{/,C:\Users\User8\workspace\QueryName-AppEngine\war}
java.lang.IllegalStateException: No such servlet: QueryServiceServlet
Regards,
Laura.
Move your <servlet-name> and <servlet-class> into their own <servlet> and see if this solves the problem. currently they are under the <servlet> element of the SystemServiceServlet.