I am working on a project and hit a brick wall. I couldn't find any resources or bug reports to solve this issue. I have a maven project setup as maven-archetype-webapp. I am new to JEE and it took me sometime to get this far but I have a better understanding of how some of this works. I have hit a brick wall and don't know how to solve the problem below.
I get the following warnings within the web.xml file
servlet-class references to non-existent class "servlets.RegisterServlet"
servlet-class references to non-existent class "servlets.HomePageServlet"
file name references to "index" that does not exist in web content
I get the following error in WildFly 10.x.
Caused by: java.lang.ClassNotFoundException: servlets.RegisterServlet from [Module "deployment.PracticeProject.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:723)
... 6 more
The java classes appear in the directory structure of the war so its packaging it correctly. For the entities, session beans and servlets I have a scope of provided for the dependencies of the pom.xml file.
My directory structure is as follows:
My web.xml file:
<?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>PracticeProject</display-name>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>servlets.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HomePageServlet</servlet-name>
<servlet-class>servlets.HomePageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomePageServlet</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
</web-app>
edit:
CHKJ3013E: The URL Mapping "" is invalid. web.xml /PracticeProject/src/main/webapp/WEB-INF org.eclipse.jst.j2ee.webapplication.internal.impl.ServletMappingImpl#53667dce (urlPattern: , name: null) Validation Message
I use NetBeans and Tomcat 7.0.4.2 and would like to change URL address of my project from localhost:8080/Servlet to localhost:8080/. In web.xml I changed servlet URL address from <url-pattern>/Servlet</url-pattern> to <url-pattern>/</url-pattern>.
The problem is I can't load resource files now and get errors in browser console log:
Failed to load resource: the server responded with a status of 404 (Not Found) (11:45:14:149 | error, network)
at src/main/webapp/scripts/aui-min_2.0.0.js
The path to resource files is src/main/webapp/scripts and in JSP file I use this path
<script type="text/javascript" src="scripts/aui-min_2.0.0.js"></script>
web.xml
<?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">
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>socialgraphui.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
The url pattern / is is used by default servlet which is capable of loading static resources that isn't mapped by other servlets. When you switched to this pattern it's stopped working. So, you should keep a servlet mapping.
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
If you want to start from the index page use a index.jsp that is listed in <welcome-file-list> configuration. The index page can redirect to the servlet using
response.sendRedirect(request.getContextPath() +"/Servlet");
To load static resource use servlet context path like that
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/aui-min_2.0.0.js"></script>
I have started learning servlet programming. I am using eclipse IDE. I have created a simple dynamic web project and have one html file and one servlet program in it(LoginForm.html & LoginServlet.java). I want to display the html page to the user at first .I have also set up the welcome-file-list tag in the web.xml but when I run the project it doesn't display that page. I also tried to enter the url in the browser manually but it's also not working.It is giving the error as '404-Page not found'. My web.xml file is
<?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>LoginApp</display-name>
<welcome-file-list>
<welcome-file>LoginForm.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.myprograms.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/logapp</url-pattern>
</servlet-mapping>
</web-app>
The URL I am using is http://localhost:8001/LoginApp/LoginForm.html. Please suggest any solution.
This question already has answers here:
Getting error: The content of element type "web-app" must match,
(3 answers)
Closed 5 years ago.
I am getting an error in my GWT application being developed in Eclipse. It's in the web.xml file. Here's the error:
The content of element type "web-app" must match "(icon?,display- name?,description?,distributable?,context-
param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-
file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-
role*,env-entry*,ejb-ref*,ejb-local-ref*)".
I have seen numerous posts about this and the problem is the order of the elements of the file, but that fix doesn't work for me (I have also tried putting all the <servlet-mapping> tags right after the corresponding <servlet>, it did not work either)
My web.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>com.yachtcloser.server.DispatchServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>upload</servlet-name>
<servlet-class>com.yachtcloser.server.UploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>download</servlet-name>
<servlet-class>com.yachtcloser.server.DownloadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.yachtcloser.server.LoginServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<url-pattern>/dispatch.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>upload</servlet-name>
<url-pattern>/upload.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Yc.html</welcome-file>
</welcome-file-list>
</web-app>
Are there any other ways of tracking this error; other files that are linked to this?
well, as per new format of DTD web-app tag might contains following tags.
<!ELEMENT web-app (icon?, display-name?, description?, distributable?,
context-param*, filter*, filter-mapping*, listener*, servlet*,
servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?,
error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*,
login-config?, security-role*, env-entry*, ejb-ref*, ejb-local-ref*)>
above mentioned icon, display-name, description, distributable....etc are in the same order as they have mentioned in the DTD file.
e.g. if you put description tag before display-name it gives error.
I deleted the file and pasted the text from the old one into a new file with the same name and now there's no errors.
Just for a reference: A SelectAll->Cut->Save->Paste->Save also fixes the problem. Probably there is a line ending character issue.
I followed the suggestion for "copy all" - "cut" - "paste" - "save" and this seemed to clear up the message. I found that in the "pasted" version all tabs had been converted to spaces.
So it seems that the web.xml validator in Eclipse does not like tabs.
The error itself gives you the clue. The order of the elements in your web.xml should follow the order specified in the error.
<displayname>
</displayname>
<description>
</description>
....... like this the elements should be in order as it says in the error.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>MyController</servlet-name>
<servlet-class>com.pk.MyController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>/MyController</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I have this configuration, but unable to access hzhfyp.com/MyController (PAGE NOT FOUND)
The Path for MyController servelet is WEB-INF/classes/com/pk/MyController.class
Although index.jsp is loaded accuratelty. Demo here http://hzhfyp.com/ Clicking any button will generate js error visible in Firebug(firefox) as Page not Found.
URLs are case sensitive. You've mapped it on /MyController with M, but your jQuery code is calling it by /myController with m. Fix it accordingly.
As to the servlet returing a 404 in spite of the correct URL, this can happen when the servlet failed to initialize or when you didn't deploy the correct web.xml at all. Read the server startup logs for any errors during servlet initialization and verify if you're deploying with the right web.xml.