JSP 上传图片之前先在页面生成预览
JSP 页面代码: <form action="#" name="uploadForm" method="post" enctype="multipart/form-data"> <input type="file" name="upload" id="upload" onchange="loadImageFile(event)"> <img id="image" src="" > <input type="submit" value="上传"> </form> JS 代码: function loadImageFile(event) { var image = document.getElementById('image'); image.src = URL.createObjectURL(event.target.files[0]); };