ff19970721
ff19970721
采纳率66.7%
2017-05-31 12:19

HTTP Status 404 description 求帮忙

java课程作业,已经配置成功tomcat,并可以实现登录界面,但是在修改的过程中由于我加了注册功能,出现了错误,如图
图片说明
其中register.jsp的代码为

<%@ page language="java" import="java.util." pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">







请输入帐号:


请输入密码:


请确认密码:





${msg }












registeredservlet.java的代码为:
package casecom.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import casecom.bean.user;
import util.JdbcConnecter;

public class RegisterServlet {
private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request, HttpServletResponse response)  
        throws ServletException, IOException {  

    user u = new user();                       //声明一个user类对象,用来储存用户输入的信息
    request.setCharacterEncoding("UTF-8");     //定义传入数据的格式,防止中文乱码
    u.setUsername(request.getParameter("username"));    //获得用户输入的用户名栏的内容,并赋值于user类的username。
    u.setPassword(request.getParameter("password"));    //获得用户输入的密码栏的内容,并赋值于user类的password。
    u.setParameter(request.getParameter("rpsw"));//得到表单输入的内容  
    if(u.getUsername().equals("")){  
        request.setAttribute("msg", "帐号不能为空");  
        request.getRequestDispatcher("/regist.jsp").forward(request, response);  
        return;  
    }  
    if(u.getPassword().equals("")){  
        request.setAttribute("msg", "密码不能为空");  
        request.getRequestDispatcher("/regist.jsp").forward(request, response);  
        return;  
    }  
    if(!u.getPassword().equals(u.getParameter())){  
        request.setAttribute("msg", "两次输入的密码不同");  
        request.getRequestDispatcher("/regist.jsp").forward(request, response);  
        return;  
    }  
    JdbcConnecter  j = new JdbcConnecter ();  
    j.addUser(u.getUsername(),u.getPassword());//调用addUser()方法  
    request.setAttribute("msg", "恭喜:"+u.getUsername()+",注册成功");  
    request.getRequestDispatcher("/index.jsp").forward(request, response);  

}  

}
修改后的web.xml是
<?xml version="1.0" encoding="UTF-8"?>
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">


This is the description of my J2EE component
This is the display name of my J2EE component
LoginServlet
casecom.Servlet.LoginServlet


This is the description of my J2EE component
This is the display name of my J2EE component
Servlet
casecom.Servlet.Servlet


This is the description of my J2EE component
This is the display name of my J2EE component
AbServlet
casecom.Servlet.AbServlet


This is the description of my J2EE component
This is the display name of my J2EE component
RegisterServlet
casecom.Servlet.RegisterServlet


LoginServlet
/servlet/LoginServlet


Servlet
/Servlet


AbServlet
/servlet/AbServlet


RegisterServlet
/servlet/RegisterServlet



index.jsp


之前登录实现也是好的,一注册就出错了,求大神解决~

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • qq_35928356 Ply to windward 4年前

    404基本上就是路径导致的

    点赞 评论 复制链接分享
  • Wondser wondser 4年前

    地址错了,应该是servlet/RegisterServlet

    点赞 2 评论 复制链接分享
  • qzcsu 小书go 4年前

    404资源找不到,应该是你表单提交的路径和你配置的路径不一样,可能某个字母写错了,仔细查看下把

    点赞 评论 复制链接分享
  • qq_35928356 Ply to windward 4年前

    表单提交的地址和servlet的匹配吗?

    点赞 评论 复制链接分享