- 文件上传
导包
Springmvc.xml配置支持文件上传
Html/JS
第一种(失败了)
|
第二种:
<%-- Created by IntelliJ IDEA. User: gyf Date: 2018/5/25 Time: 10:25 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script> <script src="${pageContext.request.contextPath}/js/jquery.form.js"></script> <title>编辑商品</title> <script type="text/javascript"> function sumbitImage() { alert("提交图片到后台"); var dataoptions={ type:'post', url:'${pageContext.request.contextPath}/upload/itemspic.do', success:function (respData) { //var jsonObj = $.parseJSON(respData); var obj =JSON.parse(respData); $('#pic').attr('src',obj.imgUrl); console.log(obj.imgUrl); $('#hiddenPic').val(obj.imgUrl) } } $('#itemsForm').ajaxSubmit(dataoptions) } </script> </head> <body> <form id="itemsForm" action="${pageContext.request.contextPath}/items/update.do" method="post"> <table border="1"> <tr> <td>名称</td> <td> <input type="text" name="name" value="${items.name}"></td> <input type="hidden" name="id" value="${items.id}"></td> </tr>