I have 3 servlets in my web application.
The first servlet is workinh OK.
The second and third servlet which is copying from the first one, doesn't work and doesn't get response.
However, I search on internet and all websites say: the error in web.xml file
This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1">
<servlet>
<servlet-name>getmarks</servlet-name>
<servlet-class>getmarks</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>Login</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Enter</servlet-name>
<servlet-class>Enter</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>getmarks</servlet-name>
<url-pattern>/getmarks</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Enter</servlet-name>
<url-pattern>/Enter</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
Try This Code 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>Your Project Name</display-name>
<servlet>
<servlet-name>ABC</servlet-name>
<servlet-class>getmarks</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>DEF</servlet-name>
<servlet-class>Login</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>GHI</servlet-name>
<servlet-class>Enter</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ABC</servlet-name>
<url-pattern>/getmarks_1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DEF</servlet-name>
<url-pattern>/Login_1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GHI</servlet-name>
<url-pattern>/Enter_1</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
You should put full class names in the <servlet-class> tag.
Also, <web-app> tag is missing some attributes about XML Schema. You can find more information here.
For version 3.1 it should look like this:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
// your mappings
</web-app>
Closing </web-app> tag is also missing.
Related
I am making a dynamic web project with mysql database connectivity in eclipse using dynamic web module 3.0,jdk 1.7
This is my project structure
Project structure
web.xml for it
<?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>Project</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>AdminLogin</servlet-name>
<servlet-class>com.servlets.AdminLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>AddBook</servlet-name>
<servlet-class>com.servlets.AddBook</servlet-class>
</servlet>
<servlet>
<servlet-name>AddBookForm</servlet-name>
<servlet-class>com.servlets.AddBookForm</servlet-class>
</servlet>
<servlet>
<servlet-name>AddLibrarian</servlet-name>
<servlet-class>com.servlets.AddLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>AddLibrarianForm</servlet-name>
<servlet-class>com.servlets.AddLibrarianForm</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteBook</servlet-name>
<servlet-class>com.servlets.DeleteBook</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteLibrarian</servlet-name>
<servlet-class>com.servlets.DeleteLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>EditLibrarian</servlet-name>
<servlet-class>com.servlets.EditLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>IssueBook</servlet-name>
<servlet-class>com.servlets.IssueBook</servlet-class>
</servlet>
<servlet>
<servlet-name>IssueBookForm</servlet-name>
<servlet-class>com.servlets.IssueBookForm</servlet-class>
</servlet>
<servlet>
<servlet-name>LibrarianLogin</servlet-name>
<servlet-class>com.servlets.LibrarianLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutAdmin</servlet-name>
<servlet-class>com.servlets.LogoutAdmin</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutLibrarian</servlet-name>
<servlet-class>com.servlets.LogoutLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>ReturnBook</servlet-name>
<servlet-class>com.servlets.ReturnBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewBook</servlet-name>
<servlet-class>com.servlets.ViewBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewIssuedBook</servlet-name>
<servlet-class>com.servlets.ViewIssuedBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewLibrarian</servlet-name>
<servlet-class>com.servlets.ViewLibrarian</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminLogin</servlet-name>
<url-pattern>/AdminLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddBook</servlet-name>
<url-pattern>/AddBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddBookForm</servlet-name>
<url-pattern>/AddBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddLibrarian</servlet-name>
<url-pattern>/AddLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddLibrarianForm</servlet-name>
<url-pattern>/AddLibrarianForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteBook</servlet-name>
<url-pattern>/DeleteBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteLibrarian</servlet-name>
<url-pattern>/DeleteLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EditLibrarian</servlet-name>
<url-pattern>/EditLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EditLibrarianForm</servlet-name>
<url-pattern>/EditLibrarianForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>IssueBook</servlet-name>
<url-pattern>/IssueBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>IssueBookForm</servlet-name>
<url-pattern>/IssueBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LibrarianLogin</servlet-name>
<url-pattern>/LibrarianLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutAdmin</servlet-name>
<url-pattern>/LogoutAdmin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutLibrarian</servlet-name>
<url-pattern>/LogoutLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ReturnBook</servlet-name>
<url-pattern>/ReturnBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ReturnBookForm</servlet-name>
<url-pattern>/ReturnBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewBook</servlet-name>
<url-pattern>/ViewBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewIssuedBook</servlet-name>
<url-pattern>/ViewIssuedBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewLibrarian</servlet-name>
<url-pattern>/ViewLibrarian</url-pattern>
</servlet-mapping>
</web-app>
I have included mysql-connector.jar in java resources/lib only.
When i am running it it shows
HTTP ERROR: 503
Problem accessing /Project/AdminLogin. Reason:
Service Unavailable
Powered by Jetty://
But when I am using the web.xml as
<?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>Project</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>AdminLogin</servlet-name>
<servlet-class>com.servlets.AdminLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminLogin</servlet-name>
<url-pattern>/AdminLogin</url-pattern>
</servlet-mapping>
</web-app>
it opens the AdminLogin page but after that when I open other servlets it shows error as
HTTP ERROR 404
Problem accessing /Project/AddLibrarianForm. Reason:
Not Found
Is the problem due to my web.xml file or something else?
I create a web application in Netbeans, named test9. I have create various jsp files and servlets,etc in it.Now i want to change the starting page index.html to index.jsp so I created a new file index.jsp and deleted index.html but after running it, It is still trying to open index.html and displaying 404 error resource not found i even made changes in my xml file but still it is doing it.
Do i have to make some other changes ?
xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>RequestLoggingFilter</filter-name>
<filter-class>bean.RequestLoggingFilter</filter-class>
</filter>
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>bean.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>RequestLoggingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>bean.LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>bean.LogoutServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DepartmentServlet</servlet-name>
<servlet-class>bean.DepartmentServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>C_userServlet</servlet-name>
<servlet-class>bean.C_userServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>statusServlet</servlet-name>
<servlet-class>bean.statusServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>FileServlet</servlet-name>
<servlet-class>bean.FileServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>bean.SearchServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>NoCacheFilter</servlet-name>
<servlet-class>bean.NoCacheFilter</servlet-class>
</servlet>
<servlet>
<servlet-name>forgotServlet</servlet-name>
<servlet-class>bean.forgotServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>passServlet</servlet-name>
<servlet-class>bean.passServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/LogoutServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DepartmentServlet</servlet-name>
<url-pattern>/DepartmentServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>C_userServlet</servlet-name>
<url-pattern>/C_userServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>statusServlet</servlet-name>
<url-pattern>/statusServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>/FileServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SearchServlet</servlet-name>
<url-pattern>/SearchServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>NoCacheFilter</servlet-name>
<url-pattern>/NoCacheFilter</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>forgotServlet</servlet-name>
<url-pattern>/forgotServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
In netBeans you can right click button on your project, then properties. A new pop up window will open, and on the left menu there will be a label call run. Click there and then in the "relative URL" you should put
/nameOfYourJspFile.jsp
and it works but i still do not know why
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
did not work.
I know that this is an old post but since i had the same issue and solved it i am posting my answer to help some others who might stuck in a situation like this.
What worked for me was to take the new jsp file out of the WEB-INF folder.
I am developing JAVA web project by using netbeans IDE, I want to display some images from a folder outside the project's directory, after uploading them by my servlets, here is my code:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>views/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>controllers.LoginController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>index</servlet-name>
<jsp-file>/views/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>students</servlet-name>
<servlet-class>controllers.StudentController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>students</servlet-name>
<url-pattern>/students</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>books</servlet-name>
<servlet-class>controllers.BookController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>books</servlet-name>
<url-pattern>/books</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>admins</servlet-name>
<servlet-class>controllers.AdminController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admins</servlet-name>
<url-pattern>/admins</url-pattern>
</servlet-mapping>
<context-param>
<param-name>uploads</param-name>
<param-value>C:/Users/mohammad/Documents/NetBeansProjects/uploads</param-value>
</context-param>
</web-app>
img in the jsp:
<img src="C:/Users/mohammad/Documents/NetBeansProjects/uploads/name.jpg"/>
servlet:
I am sending it inside a json object:
object.add("<img src=\""+getServletContext().getInitParameter("uploads")+"/"+book.getImage()+"\"/>");
I am sure that the image is exist in that folder, but it couldn't loaded, what is the problem here?
You should add filter on web.XML file of image extensions that actually specify that what kind of external resources can be passed through front controller.. Will u please post your web.xml
U may try this link Upload an image to a Path set in web.xml using primefaces
I have index.html in my WEB-INF folder. I want it to be loaded when I go to localhost:8080/myapp. But unfortunately I am getting 404.
Could you please let me know what do I need to modify in order achieve that?
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>${project.name} (${project.version})</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>com.skygraph.facade</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is the follow up of this question how to remove .py from the url in jython , I couldnt get it solved till now, and hope to get some more suggestions for it.
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" >
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>NewJythonServlet</servlet-name>
<servlet-class>NewJythonServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NewJythonServlet</servlet-name>
<url-pattern>/NewJythonServlet</url-pattern>
</servlet-mapping>
</web-app>
any ideas please?
Try:
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>/serv/*</url-pattern>
</servlet-mapping>
I think the url had to start with something that isn't a wildcard