【JSP实现图片上传并保存到数据库】

JSP实现图片上传并保存到数据库

开发工具与关键技术:Eclipse Java
撰写时间:2020年9 月 28 日

今天分享一个jsp页面图片上传的案例demowebs

准备工作: 准备依赖包:commons-fileupload-1.3.2.jar、commons-io-2.5.jar,并将准备的包存放在/项目名称/WebContent/WEB-INF/lib文件夹中。
在这里插入图片描述
接着在jsp页面添加form表单,表单用post提交,注意 enctype 属性值还要设置为enctype="multipart/form-data",在上传单个文件的时候,应该使用单个带有属性type="file"<input .../> 标签。有些时候为了允许多个文件上传,就会用多个name属性值不同的input标签来实现,输入标签具有不同的名称属性的值,浏览器会为每个input标签关联一个【浏览】按钮。

jsp代码:
在这里插入图片描述

   <div class="col-md-12">
	        	<div class="col-md-6 col-md-offset-3">
	        		<form id="formUserInsert" action="${ctx}/servlet/usersServlet?fun=doInsert" class="form-horizontal form-radius" method="post" enctype="multipart/form-data">
	                    <input type="reset" name="reset" style="display: none;"/>
	                    <div class="form-group form-group-sm">
	                        <label class="control-label col-sm-3" for="userName">用户名</label>
	                        <div class="col-sm-9">
	                            <input type="text" class="form-control" id="userName" name="userName">
	                        </div>
	                    </div>
	                    <div class="form-group form-group-sm">
	                        <label class="control-label col-sm-3" for="password">密码</label>
	                        <div class="col-sm-9">
	                            <input type="text" class="form-control" id="password" name="password">
	                        </div>
	                    </div>
	                    <div class="form-group form-group-sm">
	                        <label class="control-label col-sm-3" for="userTypeId">用户类型</label>
	                        <div class="col-sm-9">
	                            <select class="form-control" id="userTypeId" name="userTypeId" >
	                            	<c:forEach items="${userTypes}" var="userType">
	                            		<option value="${userType.userTypeId}">${userType.userType}</option>
	                            	</c:forEach>
	                            </select>
	                        </div>
	                    </div>
	                    <div class="form-group form-group-sm">
	                        <label class="control-label col-sm-3" for="sex">性别</label>
							<div class="col-sm-9">
								<select class=
  • 24
    点赞
  • 158
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值