老师报错啦,帮忙看一下呗

老师报错啦,帮忙看一下呗

[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)

下面是页面

<%@ 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中的方法

	/**
	 * 修改产品的方法
	 * @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()这个方法中的参数为空。但是也不能为空吧。现在找不到原因老师。

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

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

1回答
好帮手慕柯南 2019-09-19 11:32:06

同学你好!

  1. 同学的代码在老师这里并没有报第一个错误

  2. 同学的代码报第一个错误,应该map并不能够接收到数据。所以建议同学先解决第一个错误,同学clean一下项目,重新启动测试一下。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 飞天小栗旬 #1
    老师,这个问题我解了。点错按键了。自然没有enctype属性。昨天秀逗了
    2019-09-19 11:49:25
  • 好帮手慕柯南 回复 提问者 飞天小栗旬 #2
    好的同学,解决了就好,加油,祝学习愉快~
    2019-09-19 12:06:32
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

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