我正在尝试使用名称和密码创建一个简单的表单。但是当我点击我的表格上的验证按钮“铭文”时,我收到错误404.我的错误是:ETAT 404 HTTP- /题词 类型:Rapport d'état 消息:/题字 描述:ressource不可用 这就是我的全部。
我应该得到一个空白页面,因为我的帖子方法中没有任何内容。
这是我的新 JSP文件inscription.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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=UTF-8">
<title>Inscription</title>
<link type="text/css" rel="stylesheet" href="<c:url value="/inc/style.css"/>" />
</head>
<body>
<form method="post" action="/inscription">
<fieldset>
<legend>Inscription</legend>
<p>Vous pouvez vous inscrire via ce formulaire.</p>
<label for="email">Adresse email <span class="requis">*</span></label>
<input type="text" id="email" name="email" value="" size="20" maxlength="60" />
<br />
<label for="motdepasse">Mot de passe <span class="requis">*</span></label>
<input type="password" id="motdepasse" name="motdepasse" value="" size="20" maxlength="20" />
<br />
<label for="confirmation">Confirmation du mot de passe <span class="requis">*</span></label>
<input type="password" id="confirmation" name="confirmation" value="" size="20" maxlength="20" />
<br />
<label for="nom">Nom d'utilisateur</label>
<input type="text" id="nom" name="nom" value="" size="20" maxlength="20" />
<br />
<input type="submit" value="Inscription" class="sansLabel" />
<br />
</fieldset>
</form>
</body>
</html>
这是我的新 servlet Inscription.java:
package com.sdzee.pro.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Inscription
*/
@WebServlet( "/inscription" )
public class Inscription extends HttpServlet {
private static final long serialVersionUID = 1L;
public static final String VUE = "/WEB-INF/inscription.jsp";
/**
* @see HttpServlet#HttpServlet()
*/
public Inscription() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append( "Served at: " ).append( request.getContextPath() );
this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
public void doPost( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet( request, response );
}
}
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>Inscription</servlet-name>
<servlet-class>com.sdzee.pro.servlets.Inscription</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Inscription</servlet-name>
<url-pattern>/inscription</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:0)
错误404表示无法找到您尝试访问的资源。因此,您的Servlet的URL映射存在问题。
<form method="post" action="<c:url value="/inscription"/>">
这是不正确的,您需要转义这样的引号:
<form method="post" action="<c:url value=\"inscription\">">
但是如果你知道你的URL映射,为什么不用相对路径对它进行硬编码呢? (&#39; ..&#39;用于上传目录)
<form method="post" action="../inscription">
修改强>
注意到与您的网址映射不一致......
你的web.xml中的是:
<url-pattern>/inscription</url-pattern>
但是你有一个servlet注释:
@WebServlet( "/Inscription" )
这也会给你带来麻烦。确保它们是相同的。更改注释以匹配您的web.xml servlet映射:
@WebServlet( "/inscription" )
URL Servlet映射区分大小写。