麦兜的光辉 2018-10-12 08:52 采纳率: 66.7%
浏览 1310
已采纳

SSM写的增删改查jsp跳转404不报错

 @RequestMapping("/list")
    public String getList(ModelMap map) {
        List<Student> students = userService.getTotal();
        map.addAttribute("students", students);
        // System.out.println(userService.getTotal());
        return "/index.jsp";

    }

    @RequestMapping("/addStudent")
    public String addStudent(HttpServletRequest request,
            HttpServletResponse response) {

        Student student = new Student();

        int studentID = Integer.parseInt(request.getParameter("student_id"));
        String name = request.getParameter("name");
        int age = Integer.parseInt(request.getParameter("age"));
        String sex = request.getParameter("sex");
        Date birthday = null;
        // String 类型按照 yyyy-MM-dd 的格式转换为 java.util.Date 类
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            birthday = simpleDateFormat.parse(request.getParameter("birthday"));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        System.out.println(userService.getTotal());

        student.setStudent_id(studentID);
        student.setName(name);
        student.setAge(age);
        student.setSex(sex);
        student.setBirthday(birthday);

        userService.addStudent(student);

        return "redirect:index.jsp";
    }

    @RequestMapping("/deleteStudent")
    public String deleteStudent(int id) {
        userService.deleteStudent(id);
        return "redirect:index.jsp";
    }

    @RequestMapping("/editStudent")
    public ModelAndView editStudent(int id) {
        ModelAndView mav = new ModelAndView("editStudent");
        Student student = userService.getStudent(id);
        mav.addObject("student", student);
        return mav;
    }


<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="jquery-2.1.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<title>学生管理页面 - 首页</title>
<script>
    $(function() {
        $("ul.pagination li.disabled a").click(function() {
            return false;
        });
    });
    function del() {
        var msg = "您真的确定要删除吗?\n\n请确认!";
        if (confirm(msg) == true) {
            return true;
        } else {
            return false;
        }
    }
</script>
</head>
<body>
    <div class="listDIV">
        <table border="1" width="50%" height="50%" style="text-align: center;">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>出生日期</th>

                <th>操作</th>
            </tr>
            <c:forEach items="${students}" var="s" varStatus="status">
                <tr>
                    <td>${s.student_id}</td>
                    <td>${s.name}</td>
                    <td>${s.age}</td>
                    <td>${s.sex}</td>
                    <td>${s.birthday}</td>

                    <td><a href="/editStudent?id=${s.id}"><span
                            class="glyphicon glyphicon-edit"></span> 修改</a> <a
                        href="/deleteStudent?id=${s.id}"
                        onclick="javascript:return del();"><span
                            class="glyphicon glyphicon-trash"></span> 删除</a></td>
                </tr>
            </c:forEach>
        </table>
    </div>
    <a href="addStudent.jsp">添加学生</a>
</body>
</html>


    <div class="addDIV">

        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">添加学生</h3>
            </div>
            <div class="panel-body">

                <form method="post" action="/addStudent" role="form">
                    <table class="addTable">
                        <tr>
                            <td>学号:</td>
                            <td><input type="text" name="student_id" id="student_id"
                                placeholder="请在这里输入学号"></td>
                        </tr>
                        <tr>
                            <td>姓名:</td>
                            <td><input type="text" name="name" id="name"
                                placeholder="请在这里输入名字"></td>
                        </tr>
                        <tr>
                            <td>年龄:</td>
                            <td><input type="text" name="age" id="age"
                                placeholder="请在这里输入年龄"></td>
                        </tr>
                        <tr>
                            <td>性别:</td>
                            <td><input type="radio" class="radio radio-inline"
                                name="sex" value="男"> 男 <input type="radio"
                                class="radio radio-inline" name="sex" value="女"> 女</td>
                        </tr>
                        <tr>
                            <td>出生日期:</td>
                            <td><input type="date" name="birthday" id="birthday"
                                placeholder="请在这里输入出生日期"></td>
                        </tr>
                        <tr class="submitTR">
                            <td colspan="2" align="center">
                                <button type="submit" class="btn btn-success">提 交</button>
                            </td>

                        </tr>

                    </table>
                </form>
            </div>
        </div>
    </div>

<div class="editDIV">

    <div class="panel panel-success">
        <div class="panel-heading">
            <h3 class="panel-title">编辑学生</h3>
        </div>
        <div class="panel-body">

            <form method="post" action="/updateStudent" role="form">
                <table class="editTable">
                    <tr>
                        <td>学号:</td>
                        <td><input type="text" name="student_id" id="student_id" value="${student.student_id}"
                                   placeholder="请在这里输入学号"></td>
                    </tr>
                    <tr>
                        <td>姓名:</td>
                        <td><input type="text" name="name" id="name" value="${student.name}" placeholder="请在这里输入名字">
                        </td>
                    </tr>
                    <tr>
                        <td>年龄:</td>
                        <td><input type="text" name="age" id="age" value="${student.age}" placeholder="请在这里输入年龄"></td>
                    </tr>
                    <tr>
                        <td>性别:</td>
                        <td><input type="radio" class="radio radio-inline" name="sex" value="男"> 男
                            <input type="radio" class="radio radio-inline" name="sex" value="女"> 女
                        </td>
                    </tr>
                    <tr>
                        <td>出生日期:</td>
                        <td><input type="date" name="birthday" id="birthday" value="${student.birthday}"
                                   placeholder="请在这里输入出生日期"></td>
                    </tr>
                    <tr class="submitTR">
                        <td colspan="2" align="center">
                            <input type="hidden" name="id" value="${student.id}">
                            <button type="submit" class="btn btn-success">提 交</button>
                        </td>

                    </tr>

                </table>
            </form>
        </div>
    </div>

</div>


  • 写回答

3条回答 默认 最新

  • 爱打架的小白兔 2018-10-12 09:16
    关注

    404路径访问不到.检查你的访问路径是否正确.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题