xushuimeng 2021-12-08 22:43 采纳率: 33.3%
浏览 61
已结题

java.lang.NumberFormatException: null

java.lang.NumberFormatException: null
<body>
    <div id="container">
        <div id="header">
            <a id="quit" href="QuitServlet">退出</a>
            <h1>宠物医院</h1>
            <ul id="menu">
                <li><a href="vetsearch.jsp">医生管理</a></li>
                <li><a href="customersearch.jsp">客户管理</a></li>
            </ul>
        </div><!--  -->
        <div id="content">
            <form action="PetServlet?id=${requestScope.id}" method="post" enctype="multipart/form-data">
                <table>
                <tr><td><input type="text" value="${requestScope.id}" name="cusId"/></td></tr>
                    <tr>
                    <td>主人姓名</td>
                    <td><input type="text" name="customerName" value="${requestScope.name}"></td>
                </tr>
                <tr>
                    <td>宠物姓名</td>
                    <td><input type="text" name="petName"></td>
                </tr>
                <tr>
                    <td>出生日期</td>
                    <td><input type="text" name="petBirthday"></td>
                </tr>
                <tr>
                    <td>宠物照片</td>
                    <td><input id="title" name="photo" value="" type="file"></td>
                </tr>
                <td><input  type="submit" value="添加" /> </td>
                <td><input type="reset" value="重置"/></td>

                </table>
            </form>
            <%-- TODO: --%>
            
        </div>
        <div id="footer"></div>
    </div>
</body>


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String ii=request.getParameter("id");
        System.out.print(2);
        System.out.print(ii);
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=GBK");
        SmartUpload su = new SmartUpload();
        //初始化
        su.initialize(this.getServletConfig(), request, response);
        //上传过程
        try {
            su.upload();
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SmartUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //获取上传文件对象
        Files fs = su.getFiles();
        File f = fs.getFile(0);
        //获取上传的文件名
        
        String fname  = f.getFileName();
        try {
            su.save("/images");
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SmartUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //Request reql = su.getRequest();
        String ii2=request.getParameter("cusId");
        System.out.print(2);
        System.out.print(ii2);
        
        Integer custId = Integer.parseInt(request.getParameter("cusId"));
        String petName = request.getParameter("petName");
        String petBirthday = request.getParameter("petBirthday");
        Pet pet=new Pet(1,petName,petBirthday,fname,custId);
        PetDAO petDAO=new PetDAO();
        try {
            petDAO.save(pet);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        request.setAttribute("msg", "添加成功");
        request.getRequestDispatcher("customerdetail.jsp").forward(request, response);
        //
        //    TODO:
        //
    }

img


为什么servlet中拿不到id,jsp发送过来的id接收不到

我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 关注

    这个使用了上传功能,要用su对象获取参数,
    su.getParameter("id");或者su.getRequest.getParameter("id");
    su.getParameter("cusId");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月18日
  • 已采纳回答 12月10日
  • 创建了问题 12月8日

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码