1.页面页面
<div> <span ID =“ uploadimg” style =“ margin:50px; background-color:#ddd; display:inline-block;高度:130px; width:200px;“> <span style =” color:#bbb; font-weight; font-odge; font-weight:600; 600虚假;字体大小:20px;文本 - 平均:中心;显示:内线障碍;高度:50px;宽度:50px; line-height:50px;位置;位置:绝对;边距:40px; margin-left; margin-left:75px; z-index; z-index; z-index:99“>++</span>+</span> </span> </span> <img id = impl <im spert </displut files = displut files =' style =“ display:none” name =“ imgcard” id =“ imgfilebtn” id =“ imgfilebtn” onChange =“ javascript:setimagepreview();”/> </div>
2.后台
私有文件imgcard;私有字符串imgcardContentType;私有字符串imgcardfileName; public void getimg(){base64encoder encoder = new Base64encoder(); bufferedimage bi; boolean isimage = false; string [] imgexts = {“ .jpg”,“ .jpeg”,“。bmp”,“ .png”}; for(字符串ext:imgexts){if(imgcardfilename.tolowercase()。endswith(ext)){isimage = true;休息; }} if(((imgcard.length()/1024/1024)> 3){返回错误;} bi = imageio.read(imgcard); bytearrayoutputstream baos = new bytearrayoutputstream(); image.Write(Bi,“ JPG”,Baos);字节[]字节= baos.tobytearray();字符串img = encoder.encodeBuffer(bytes).trim(); }truts2中图片以Base64方式上传至数据库,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!