问题:我的带有 web.xml 的 index.jsp 不断进入 HTTP 404 和 500
我正在使用 Tomcat6 。
这是来自 index.jsp :
<legend>Registration</legend>
<form action="./register"> <%-- Address from web.xml --%>
First name: <input type="text" name="firstName"><br>
Last name: <input type="text" name="lastName"><br>
<input type="submit" value="Register">
</form>
当我在注册时:
然后我点击姓名和姓氏,我进入 404 ,消息:
HTTP 状态 404 - Servlet RegistrationServlet 不可用
类型状态报告
消息Servlet RegistrationServlet 不可用
描述请求的资源(Servlet RegistrationServlet 不可用)不可用。
Apache Tomcat/6.0.35
您认为导致该错误的原因是什么?
该类RegistrationServlet
在文件RegistrationServlet.java
夹中的文件下src/coreservlets/
我检查了 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/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>ShowBalance</servlet-name>
<servlet-class>coreservlets.ShowBalance</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShowBalance</servlet-name>
<url-pattern>/show-balance</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RandomNumberServlet</servlet-name>
<servlet-class>coreservlets.RandomNumberServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RandomNumberServlet</servlet-name>
<url-pattern>/random-number</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegistrationServlet</servlet-name>
<servlet-class>coreservlets.RegistrationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>PrimeServlet</servlet-name>
<servlet-class>coreservlets.PrimeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PrimeServlet</servlet-name>
<url-pattern>/prime</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
在过去的两天里,我一直在努力解决这个小罪魁祸首,但没有任何帮助,我们将不胜感激。
编辑:
根据要求,这里是RegistrationServlet
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RegistrationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
synchronized (session) {
NameBean nameBean = (NameBean) session.getAttribute("name");
if (nameBean == null) {
nameBean = new NameBean();
session.setAttribute("name", nameBean);
}
nameBean.setFirstName(request.getParameter("firstName"));
nameBean.setLastName(request.getParameter("lastName"));
String address = "/WEB-INF/mvc-sharing/ShowName.jsp";
RequestDispatcher dispatcher = request
.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
}
}
这里也是项目树: