近期,由于项目需求需要上传图片logo,笔者在探索的过程中遇到过很多坑,今晚就把个人经验分享出来尽量少让博友们脑壳疼
不多bb 直接上硬菜
1.前端代码
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script charset="utf-8" src="js/kindeditor/kindeditor-all.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>图片新闻</title>
<script type="text/javascript">
function B(){
window.location.reload();
}
</script>
<script type="text/javascript">
//下面用于多图片上传预览功能
if(docObj.files[i].size>20*1024*1024){
tishi+="第"+Number(i+1)+"张图片过大,图片上传限制为20M;";
continue;
alert(tishi);
var model="title=word,resizable=yes,scrollbars=yes,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,to="+ (x-h)/2 + ",left=" + (y-w)/2;
</script>
<script type="text/javascript">
//KindEditor脚本
var editor;
KindEditor.ready(function(K) {
editor = K.create('#kindEditor_demo', {});
editor.sync();//将KindEditor的数据同步到textarea标签。
var value_content = $("#text_new_continue").val();
});
</script>
</head>
<body style="text-align: center">
<div id="dd" style=" width:500px;"></div>
<input type="submit" id="add" width="300px" value="保存" />
<input type="button" id="ESC" width="300px" value="取消" onclick="B()"/>
<input type="button" class="button" id="fh" value="返回上一级" onclick="javascript:window.history.go(-1)">
</td>
</table>
</form>
</div>
</body>
</html>
</body>
</html>
2.Controller
@RequestMapping("/doupload")
List list = new ArrayList();
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
3.util
文章来源: Java实现图片上传到服务器