Following my previous post here , I've removed all my source files into a package called model
, and now the project refuses to load while executing http://localhost:8080/MyFirstServlet
.
I suspect the culprit is web.xml
, here's the file :
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" 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>MyFirstServlet</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>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>model.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/model/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
[1]: https://stackoverflow.com/questions/11282231/jsp-page-wont-move-the-another-page-after-user-enters-the-input/11283006#11283006
this is index.jsp:
<%@ page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
<form action="model/LoginServlet" method="POST">
First Name: <input type="text" name="firstName" size="20"><br>
Last Name: <input type="text" name="lastName" size="20">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
This is the hierarchy of the project :
When I execute http://localhost:8080/MyFirstServlet
and reach here :
I enter first
and second
into the text fields and then get this :
I've tried to fix it but nothing did , so I'd appreciate any advice , thanks :)
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>model.LoginServlet</servlet-class>
</servlet>
You missed the package for the servlet-class.
You form action should be
<form action="model/LoginServlet" />
and your Login servlet should define the package correctly.
package model;
Also your web.xml must declare this servlet class through fully qualified name
model.LoginServlet
Your servlet must extend HttpServlet.
If you make sure that all of the above are in place correctly and it still doesn't work. Then, You may need to check your build path settings in eclipse for this project.
stacktrace清楚地显示了错误,ClassNotFoundException意味着servlet Container无法在web.xml中找到指定的Class。
LoginServlet.java中的第一行代码应该是
package model;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.