I am writing a simple reservation request for one of my homework assignments. My reservation booking website has a login, check-in, flight search, results display and JSP confirmation pages. I want to call servlets when a user tries to perform an action, for example:
The user goes to login.jsp and clicks the "Login" button, the form has a target / kernel / Login (the kernel is my main servlets, and Login is the corresponding servlet that should handle this request).
In our previous homework, we wrote our own web server, so I didn’t use Tomcat to deploy serlvet ... now that we no longer use our own web server, I am having problems figuring out how to run servlets in Eclipse .
I created a dynamic web project in Eclipse and automatically created the following folder structure:
../P3 ../P3/src ../P3/src/core ../P3/build ../P3/WebContent ../P3/WebContent/META-INF ../P3/WebContent/WEB-INF
My login.jsp has a form that, when filled and clicked, sends the results to the Login servlet in my main package:
<form name="input" action="src/core/Login" method=GET> Username: <input type="text" name="userName" /> <br> Password: <input type="password" name="password" /> <br> <input type="submit" value="Login" /> </form>
Eclipse has a built-in browser, so when I run login.jsp, it loads it into the Eclipse browser and displays it. When I click the Login button, it should send the username and password to the Login servlet, but instead I get the following message:
HTTP Status 404 - /P3/src/core/Login -------------------------------------------------------------------------------- type Status report message /P3/src/core/Login description The requested resource (/P3/src/core/Login) is not available.
For some reason, the server does not know about the servlet ... I read a couple ( first and second ) articles on the Internet explaining possible problems, but I still get the error. I tried the solution in the first article and it did not work; the second article did not actually apply, since the server settings.xml file already contained the correct flags and directories.
Here is my WEB-INF / 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>P3</display-name> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>Registration</display-name> <servlet-name>Registration</servlet-name> <servlet-class>core.Registration</servlet-class> </servlet> <servlet-mapping> <servlet-name>Registration</servlet-name> <url-pattern>/Registration</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>Register</display-name> <servlet-name>Register</servlet-name> <servlet-class>core.Register</servlet-class> </servlet> <servlet-mapping> <servlet-name>Register</servlet-name> <url-pattern>/Register</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>Login</display-name> <servlet-name>Login</servlet-name> <servlet-class>core.Login</servlet-class> </servlet> <servlet-mapping> <servlet-name>Login</servlet-name> <url-pattern>/Login</url-pattern> </servlet-mapping> </web-app>
How do I configure my project to deploy correctly in Eclipse?