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

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 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳