消息关闭
    暂无新消息!
register.jsp内容如下:
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
<script type = "text/javascript">
function register(form){
if(form.username.value == ""){
alert("用户不能为空!");
return false;
}
if(form.password.value == ""){
alert("密码不能为空!");
return false;
}
if(form.repassword.value == ""){
alert("确认密码不能为空!");
return false;
}
if(form.password.value != form.repassword.value){
alert("两次密码输入不一致!");
return false;
}
}
</script>
</head>
<body>
<br><br><br><br>
    <form action="RegServlet" method="post" onsubmit="return register(this);">
    <table align="center">
    <tr>
        <td align="right">用户名:</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td align="right">密   码:</td>
        <td><input type="password" name="password"></td>
    </tr>
    <tr>
        <td align="right">确认密码:</td>
        <td><input type="password" name="repassword"></td>
    </tr>
    <tr>
        <td align="right">头   像:</td>
        <td><input type="textarea" style="height:120px;"" name="photo">
                <input type="button"  value="上传"></td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="submit" value="注册" >&nbsp;&nbsp;
            <input type="reset" value="重置">
        </td>
    </tr>
    </table>
  </form>
</body>
</html>

web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 主页 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 用户注册 -->
<servlet>
<servlet-name>RegServlet</servlet-name>
<servlet-class>com.whb.servlet.RegServlet</servlet-class>
</servlet>
<!-- 用户登录 -->
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.whb.servlet.LoginServlet</servlet-class>
</servlet>
<!-- Servlet映射 -->
<servlet-mapping>
<servlet-name>RegServlet</servlet-name>
<url-pattern>/RegServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<!-- 过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.whb.code.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>

结果:
HTTP Status 404 - /LoginSystem/WebContent/RegServlet

type Status report

message /LoginSystem/WebContent/RegServlet

description The requested resource is not available.

也在网上查过不少方法试着改了下,运行下来还老是出错,这要怎么解决啊?!!

3个回答

︿ 2
404是路径错误,简单的说就是你的页面找不到后台执行它的代码,原因就是你在配置文件中把路径设置错了,你可以仔细检查一下你的配置文件的路径设置
︿ 0
HTTP Status 404 - /LoginSystem/WebContent/RegServlet

WebContent/ 这一层不应该有吧。


这里改下<form action="RegServlet" method="post" onsubmit="return register(this);">
改为
<form action="/RegServlet" method="post" onsubmit="return register(this);">

再不行就用context path+servlet

<form action="<%=ctx%>/RegServlet" method="post" onsubmit="return register(this);">