老师报错啦,帮忙看一下呗
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | [Category [cid= 1 , cname=动物画, cdesc=aaa], Category [cid= 2 , cname=植物画, cdesc=bbb], Category [cid= 10 , cname=人物画, cdesc=人物画描述]] org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java: 885 ) at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java: 331 ) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java: 349 ) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java: 126 ) at com.zcl.utils.UploadUtils.uploadFile(UploadUtils.java: 48 ) at com.zcl.web.action.ProductServlet.update(ProductServlet.java: 50 ) at com.zcl.web.action.ProductServlet.doGet(ProductServlet.java: 38 ) at javax.servlet.http.HttpServlet.service(HttpServlet.java: 634 ) at javax.servlet.http.HttpServlet.service(HttpServlet.java: 741 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 231 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java: 52 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at com.zcl.web.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java: 28 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 199 ) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 96 ) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 493 ) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 137 ) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 81 ) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java: 660 ) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 87 ) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 343 ) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java: 798 ) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java: 66 ) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java: 808 ) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java: 1498 ) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java: 49 ) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java: 61 ) at java.lang.Thread.run(Unknown Source) 九月 18 , 2019 10 : 51 : 48 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [com.zcl.web.action.ProductServlet] in context with path [/shop1] threw exception java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at com.zcl.web.action.ProductServlet.update(ProductServlet.java: 54 ) at com.zcl.web.action.ProductServlet.doGet(ProductServlet.java: 38 ) at javax.servlet.http.HttpServlet.service(HttpServlet.java: 634 ) at javax.servlet.http.HttpServlet.service(HttpServlet.java: 741 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 231 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java: 52 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at com.zcl.web.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java: 28 ) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 ) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 ) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 199 ) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 96 ) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 493 ) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 137 ) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 81 ) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java: 660 ) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 87 ) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 343 ) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java: 798 ) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java: 66 ) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java: 808 ) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java: 1498 ) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java: 49 ) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java: 61 ) at java.lang.Thread.run(Unknown Source) |
下面是页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> < html > <!-- Mirrored from admindesigns.com/demos/absolute/1.1/admin_forms-validation.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 06 Aug 2015 02:56:15 GMT --> < head > <!-- Meta, title, CSS, favicons, etc. --> < meta charset = "utf-8" > < title >油画商城--修改商品</ title > < link rel = "stylesheet" type = "text/css" href = "${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css" > < link rel = "stylesheet" type = "text/css" href = "${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css" > < link rel = "shortcut icon" href = "${pageContext.request.contextPath }/assets/img/favicon.ico" > </ head > < body class = "admin-validation-page" data-spy = "scroll" data-target = "#nav-spy" data-offset = "200" > < div id = "main" > <%@ include file="header.jsp"%> <%@ include file="left.jsp"%> < section id = "content_wrapper" > < section id = "content" class = "table-layout animated fadeIn" > < div class = "tray tray-center" > < div class = "content-header" > < h2 >编辑商品信息</ h2 > < p class = "lead" ></ p > </ div > < div class = "admin-form theme-primary mw1000 center-block" style = "padding-bottom: 175px;" > < div class = "panel heading-border" > < form action = "${pageContext.request.contextPath }/admin/ProductServlet?method=update" method = "post" enctype = "multipart/form-data" > < input type = "hidden" name = "pid" value = "${product.pid }" > < input type = "hidden" name = "filename" value = "${product.filename }" > < input type = "hidden" name = "path" value = "${product.path }" > < div class = "panel-body bg-light" > < div class = "section-divider mt20 mb40" > < span > 基本信息 </ span > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 名称 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "sn" class = "field" > < input id = "sn" name = "pname" class = "gui-input" placeholder = "${product.pname }" type = "text" value = "" /> </ label > </ div > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 作者 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "sn" class = "field" > < input id = "sn" name = "author" class = "gui-input" placeholder = "${product.author }" type = "text" value = "" /> </ label > </ div > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 价格 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "sn" class = "field" > < input id = "sn" name = "price" class = "gui-input" placeholder = "${product.price }" type = "text" value = "" /> </ label > </ div > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 分类 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "sn" class = "field select" > < select id = "departmentSn" name = "cid" class = "gui-input" placeholder = "分类..." > < c:forEach var = "category" items = "${categoryList}" > < option value = "${category.cid }" <c:if test = "${category.cid==product.category.cid }" >selected</ c:if >>${category.cname}</ option > </ c:forEach > </ select > < i class = "arrow double" ></ i > </ label > </ div > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 图片 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "name" class = "field" > < input id = "name" name = "filename" class = "gui-input" placeholder = "价格" type = "file" value = "上传图片" /> </ label > </ div > </ div > < div class = "section row" > < div class = "col-md-2" ></ div > < div class = "col-md-1" > < label for = "sn" class = "field prepend-icon" > < label for = "sn" class = "field-icon" > 描述 </ label > </ label > </ div > < div class = "col-md-6" > < label for = "address" class = "field" > < input id = "address" name = "address" class = "gui-input" placeholder = "${product.description }" type = "text" value = "" /> </ label > </ div > </ div > < div class = "panel-footer text-center" > < button type = "submit" class = "button" >保存</ button > < button type = "button" class = "button" onclick = "javascript:window.history.go(-1);" >返回</ button > </ div > </ div > </ form > </ div > </ div > </ div > </ section > </ section > </ div > < style > /* demo page styles */ body { min-height: 2300px; } .content-header b, .admin-form .panel.heading-border:before, .admin-form .panel .heading-border:before { transition: all 0.7s ease; } /* responsive demo styles */ @media ( max-width : 800px) { .admin-form .panel-body { padding: 18px 12px; } } </ style > < style > .ui-datepicker select.ui-datepicker-month, .ui-datepicker select.ui-datepicker-year { width: 48%; margin-top: 0; margin-bottom: 0; line-height: 25px; text-indent: 3px; color: #888; border-color: #DDD; background-color: #FDFDFD; -webkit-appearance: none; /*Optionally disable dropdown arrow*/ } </ style > < script src = "vendor/jquery/jquery-1.11.1.min.js" ></ script > < script src = "vendor/jquery/jquery_ui/jquery-ui.min.js" ></ script > < script src = "assets/admin-tools/admin-forms/js/jquery.validate.min.js" ></ script > < script src = "assets/admin-tools/admin-forms/js/additional-methods.min.js" ></ script > < script src = "assets/admin-tools/admin-forms/js/jquery-ui-datepicker.min.js" ></ script > < script src = "assets/js/utility/utility.js" ></ script > < script src = "assets/js/demo/demo.js" ></ script > < script src = "assets/js/main.js" ></ script > < script type = "text/javascript" src = "js/pages.js" ></ script > < script type = "text/javascript" src = "js/items.js" ></ script > </ body > </ html > |
下面是ProductServlet中的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /** * 修改产品的方法 * @param request * @param response * @throws IOException */ private void update(HttpServletRequest request, HttpServletResponse response) throws IOException { //1、接收参数,由于表单修改enctype属性,所以需要通过fileUpload中的API接收参数。 Map<String,String> map = UploadUtils.uploadFile(request); //2、封装数据(通过工具类获取到参数,并且存放到一个Map集合中,从map中获取参数并且封装) Product product = new Product(); product.setPid(Integer.parseInt(map.get( "pid" ))); product.setPname(map.get( "pname" )); product.setAuthor(map.get( "author" )); product.setPrice(Double.parseDouble(map.get( "price" ))); product.setDescription(map.get( "description" )); product.setFilename(map.get( "filename" )); product.setPath(map.get( "path" )); product.getCategory().setCid(Integer.parseInt(map.get( "cid" ))); //3、调用业务层面处理数据 ProductService productService = new ProductServiceImpl(); productService.update(product); //4、页面跳转 response.sendRedirect(request.getContextPath()+ "/ProductServlet?method=findAll" ); } |
在我一点击修改商品的时候就报错了。我自己在网上查了
第一个错误,可能是没有加enctype属性,我这个一直都加的。
第二个是Integer.parse()这个方法中的参数为空。但是也不能为空吧。现在找不到原因老师。
4
收起
正在回答 回答被采纳积分+1
1回答
3. Java 数据库开发与实战应用
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧