修改部门功能空指针异常

修改部门功能空指针异常

Caused by: java.lang.NumberFormatException: null

at java.lang.Integer.parseInt(Integer.java:542)

at java.lang.Integer.parseInt(Integer.java:615)

at com.imooc.sm.controller.DepartmentController.toEdit(DepartmentController.java:46)

public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Integer id=Integer.parseInt(request.getParameter("id"));

    Department department=departmentService.get(id);

    request.setAttribute("OBJ",department);
    request.getRequestDispatcher("../department_edit.jsp").forward(request,response);
}

public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Integer id=Integer.parseInt(request.getParameter("id"));
    String name=request.getParameter("name");
    String address=request.getParameter("address");

    Department department=new Department();
    department.setId(id);
    department.setName(name);
    department.setAddress(address);

    departmentService.edit(department);

    response.sendRedirect("list.do");
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=8" >
    <title>编辑部门</title>
    <link rel="stylesheet" type="text/css" href="../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/thems.css">
    <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function(){
            //自适应屏幕宽度
            window.onresize=function(){ location=location };

            var main_h = $(window).height();
            $('.hy_list').css('height',main_h-45+'px');

            var main_w = $(window).width();
            $('.xjhy').css('width',main_w-40+'px');

        });
    </script>
</head>

<body onLoad="Resize();">
<div id="right_ctn">
    <div class="right_m">
        <div class="hy_list">
            <div class="box_t">
                <span class="name">编辑部门</span>
            </div>
            <div class="space_hx">&nbsp;</div>
            <form action="edit.do" method="post" name="addForm">
                <input class="chang" type="hidden" value="${OBJ.id}">
                <div class="xjhy">
                    <!--高级配置-->
                    <ul class="hypz gjpz clearfix">
                        <li class="clearfix">
                            <span class="title">名称:</span>
                            <div class="li_r">
                                <input class="chang" name="name" type="text" value="${OBJ.name}">
                                <i>*</i>
                            </div>
                        </li>
                        <li class="clearfix">
                            <span class="title">地址:</span>
                            <div class="li_r">
                                <input class="chang" name="address" type="text" value="${OBJ.address}">
                            </div>
                        </li>
                        <li class="tj_btn">
                            <a href="javascript:history.go(-1);" class="back">返回</a>
                            <a href="javascript:addForm.submit();">保存</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>部门列表</title>
    <link rel="stylesheet" type="text/css" href="../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/thems.css">
    <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function(){
            //自适应屏幕宽度
            window.onresize=function(){ location=location };

            var main_h = $(window).height();
            $('.hy_list').css('height',main_h-45+'px');

            var search_w = $(window).width()-40;
            $('.search').css('width',search_w+'px');
            //$('.list_hy').css('width',search_w+'px');
        });
    </script>
    <!--框架高度设置-->
</head>

<body onLoad="Resize();">
<div id="right_ctn">
    <div class="right_m">
        <div class="hy_list">
            <div class="box_t">
                <span class="name">部门列表</span>
            </div>
            <div class="space_hx">&nbsp;</div>
            <!--列表-->
            <table cellpadding="0" cellspacing="0" class="list_hy">
                <tr>
                    <th scope="col">名称</th>
                    <th scope="col">地址</th>
                    <th scope="col">操作</th>
                </tr>
                <c:forEach items="${LIST}" var="dep">
                <tr>
                    <td>${dep.name}</td>
                    <td>${dep.address}</td>
                    <td>
                        <a href="toEdit.do?${dep.id}" class="btn">编辑</a>
                        <a href="remove.do?${dep.id}" class="btn">删除</a>
                    </td>
                </tr>
                </c:forEach>
            </table>
            <!--列表-->
            <!--右边底部-->
            <div class="r_foot">
                <div class="r_foot_m">
                    <a href="toAdd.do" class="btn">添加</a>
                </div>
            </div>
            <!--右边底部-->
        </div>
        <!--会议列表-->
    </div>
</div>
</body>
</html>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
提问者 慕标0359786 2020-08-19 18:51:40

解决了。。。。。。

提问者 慕标0359786 2020-08-19 18:48:46

Caused by: java.lang.NumberFormatException: null

at java.lang.Integer.parseInt(Integer.java:542)

at java.lang.Integer.parseInt(Integer.java:615)

at com.imooc.sm.controller.DepartmentController.edit(DepartmentController.java:55)

... 30 more


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师