This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 5 years ago.
The xml file is located in WebContent/WEB-INF/web.xml of my project. I am using Eclipse and running Tomcat (which is not installed via Eclipse. I prefer it to be a separate installation).
<?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" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</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>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
It doesnt work when the form page submits to the servlet. I am getting a 404 error everytime. I have been encountering this problem for a while. Somebody please help me.
You are missing <servlet>...</servlet> tag which is important to mapping. So use following :
<?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" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</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>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
and you should give action value on your form like following:
<form action="/EmployeeManagement/WebContent/Registration" method="post">
//Some code here
</form>
and also note it down all values are case sensitive on the following code:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
Your servlet name Registration should be same on both tags <servlet>...</servlet> and <servlet-mapping>...</servlet-mapping> and also package name should be same where your servlet class is located.
you have not mapped servlet name to servlet class, It should be like given below,
In <servlet-class> give the path of your servlet
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.Registration<servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
Check your form action.
Is the path there
/EmployeeManagement/WebContent/Registration
or
YOURAPPCONTEXT/EmployeeManagement/WebContent/Registration
or
YOURAPPNAME/EmployeeManagement/WebContent/Registration
You have specifyed a servlet-mapping and used the name Registration in servlet-name without defining it before.
You need to define the servlet before using it in a servlet mapping
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>[fully qualifyied name of your servlet]</servlet-class>
</servlet>
You are missing another part to define the servlet in the web.xml
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>
package.path.to.RegistrationServlet
</servlet-class>
</servlet>
You forgot a vital part of the configuration. You should add this to your web.xml before servlet-mapping tag:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.name.of.your.servlet.class</servlet-class>
</servlet>
Related
I created a angular 4 project and using JAVA REST API Project as a BackEnd. I need that I can move my angular 4 project as a staic content inside JAVA war file.
I created the production build for angular project and copy the files from dist folder and paste it inside webcontent of java project. I am able to read the index file of angular project but other files are giving 404.
Please help how can I move my angular project inside my java project to get a single war file for production.
WEB.XML :-
<?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" id="WebApp_ID" version="3.0">
<display-name>userInformation</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>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.newgen.ap2</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.newgen.ap2.CrossOrigin</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Change your web.xml to the following:
<?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" id="WebApp_ID" version="3.0">
<display-name>userInformation</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>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.newgen.ap2</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.newgen.ap2.CrossOrigin</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
The idea is to use a different Servlet to serve your static resources.
Here are some more SO posts that might be helpful:
Servlet filters' order of execution
How are Servlet url mappings in web.xml used?
What happens if I have two servlet mappings in web.xml that match a request?
After adding the context file i get this error : Statut 404 ..
my web 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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>CRUDWebAppMavenized</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>
structure
I don't know where is exactly the problem ! the 'student.jsp' page there is inside the wepapp folder.
Add this to your web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
You are probably missing the ContextLoadListener, which picks up your Spring configuration files. If this doesn't solve your issue, edit your question to include the contents of your web.xml file.
This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 5 years ago.
The xml file is located in WebContent/WEB-INF/web.xml of my project. I am using Eclipse and running Tomcat (which is not installed via Eclipse. I prefer it to be a separate installation).
<?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" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</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>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
It doesnt work when the form page submits to the servlet. I am getting a 404 error everytime. I have been encountering this problem for a while. Somebody please help me.
You are missing <servlet>...</servlet> tag which is important to mapping. So use following :
<?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" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</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>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
and you should give action value on your form like following:
<form action="/EmployeeManagement/WebContent/Registration" method="post">
//Some code here
</form>
and also note it down all values are case sensitive on the following code:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
Your servlet name Registration should be same on both tags <servlet>...</servlet> and <servlet-mapping>...</servlet-mapping> and also package name should be same where your servlet class is located.
you have not mapped servlet name to servlet class, It should be like given below,
In <servlet-class> give the path of your servlet
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.Registration<servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
Check your form action.
Is the path there
/EmployeeManagement/WebContent/Registration
or
YOURAPPCONTEXT/EmployeeManagement/WebContent/Registration
or
YOURAPPNAME/EmployeeManagement/WebContent/Registration
You have specifyed a servlet-mapping and used the name Registration in servlet-name without defining it before.
You need to define the servlet before using it in a servlet mapping
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>[fully qualifyied name of your servlet]</servlet-class>
</servlet>
You are missing another part to define the servlet in the web.xml
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>
package.path.to.RegistrationServlet
</servlet-class>
</servlet>
You forgot a vital part of the configuration. You should add this to your web.xml before servlet-mapping tag:
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>com.name.of.your.servlet.class</servlet-class>
</servlet>
web.xml
<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>TestFilter1</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>
<servlet>
<servlet-name>ser1</servlet-name>
<servlet-class>com.gaurav.test.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ser1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
index.html
<body>
HelLoSTHTML
</body>
index.jsp
<body>
HelLoSTJSP
</body>
Hello.java,implementing javax.servlet.Servlet
service method
PrintWriter out=paramServletResponse.getWriter();
out.println("HelloTextStart");
out.println(config);
out.println("HelloTextEnd");
out.close();
deployed on jboss-5.1.0GA
now cases
**requesting
/TestFilter1/
**
showing
"HelloTextStart
org.apache.catalina.core.StandardWrapperFacade#1a878065 HelloTextEnd "
but not showing
"HelLoSTHTML"
**requesting
/TestFilter1/index.html
** then also
showing
"HelloTextStart
org.apache.catalina.core.StandardWrapperFacade#1a878065 HelloTextEnd "
but not showing
"HelLoSTHTML"
**requesting
/TestFilter1/index.jsp
**
showing
"HelLoSTJSP"
So what is the order of processing/prioritizing this request?
(html,jsp.Servlet ser1)
Your application works as configured. You tell to your webapp :
When you see request coming send them to the servlet class com.gaurav.test.Hello
Conf:
<servlet>
<servlet-name>ser1</servlet-name>
<servlet-class>com.gaurav.test.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ser1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
So this servlet is responding to your request.
I think want you need is to configure the servlet javax.servlet.Servlet
I hope this will help
we can configure the URL-patterns in 3 ways
1) Absolute/Exact Matching (Ex: <url-pattern>/test1</url-pattern>)
2) Extension Matching (Ex: <url-pattern>*.do</url-pattern>)
3) Directory Matching (Ex: <url-pattern>/abc/*</url-pattern>)
<url-pattern>/</url-pattern> means Every Request go to Hello.java
First it will check Exact matching then Extension there after Directory Matching.
Above code for every request is going to Hello.java.
go through this link you will get clarity which one will be given priority in Tomcat 6: index.html or index.jsp?
I have added the following content to my web.xml for a servlet context listener---
<listener>
<listener-class>
com.anyaservices.log4j.ApplicationServletContextListener
</listener-class>
</listener>
I have added this immediately after the end of "welcome-file-list"
The last line of the welcome-file-list node is given below--
</welcome-file-list>
Now, I have made some changes to a servlet so that it can use the context listener... in addition to the servlet there is a "Hello.jsp" file that just displays a welcome message.
I have not made any changes to the JSP file. However after my code changes for the servlet context listener, when I try to go to Hello.jsp I get an error in Tomcat= The requested resource is not available.
What have I done wrong here? Why is the JSP file not being shown now?
EDIT-- I have posted the entire content of my web.xml below--
<?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 Web Application</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>Hello.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
com.test.log4j.ApplicationServletContextListener
</listener-class>
</listener>
<servlet>
<description>Used to run a single crawl job</description>
<display-name>runsinglecrawljob</display-name>
<servlet-name>runsinglecrawljob</servlet-name>
<servlet-class>com.test.runsinglecrawljob</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>runsinglecrawljob</servlet-name>
<url-pattern>/runsinglecrawljob</url-pattern>
</servlet-mapping>
<servlet>
<description>Home page</description>
<display-name>home</display-name>
<servlet-name>home</servlet-name>
<servlet-class>home</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>home</servlet-name>
<url-pattern>/home</url-pattern>
</servlet-mapping>
<servlet>
<description>Run a single crawl job after asking users for parameters of that job</description>
<display-name>runsinglejob</display-name>
<servlet-name>runsinglejob</servlet-name>
<servlet-class>com.test.runsinglecrawljob</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>runsinglejob</servlet-name>
<url-pattern>/runsinglejob</url-pattern>
</servlet-mapping>
</web-app>
The URL I am trying to access is http ://localhost:8080/test_web_app/Hello.jsp
Tomcat handles JSP files through org.apache.jasper.servlet.JspServlet. Perhaps somehow your listener class is interfering with the operation of the JspServlet. There is no need to list all of those files in your welcome file list. Any jsp file inside the war should be available (but it should not be placed inside the WEB-INF or META-INF folders.)
I think you should check your log4j configuration. Did you initialize log4j with a log4j.properties file in WEB-INF/classes?