1.页面这里输入代码
<div> <span id = "uploadimg" style = "margin:50px; background-color:#ddd; display:inline-block; height:130px; width;"> <span style = "color:#bbb; font-weight:600; border:2px#ccc破線; font-size:20px; Text-align:center; display:inline-block; height:50px; width:50px; line-height:50px; position:asbolute; magne-top:40px; margin-left:75px; z-index:99 ">+</span <img" "> </</< style = "display:none" name = "imgcard" id = "imgfilebtn" id = "imgfilebtn" onchange = "javascript:setimagepreview();"/> </div>
2.后台
プライベートファイルimgcard; private string imgcardcontenttype; private string imgcardfilename; public void getImg(){base64Encoder encoder = new base64Encoder(); bufferedimage bi; boolean isimage = false; string [] imgexts = {".jpg"、 ".jpeg"、 "。bmp"、 ".png"}; for(string ext:imgexts){if(imgcardfilename.tolowercase()。endswith(ext)){isimage = true;壊す; }} if((imgcard.length()/1024/1024)> 3){return error;} bi = imageio.read(imgcard); bytearrayoutputStream baos = new bytearrayoutputStream(); Imageio.write(bi、 "jpg"、baos); byte [] bytes = baos.tobytearray(); string img = encoder.encodebuffer(bytes).trim(); }以上所述是小编给大家介绍的struts2 base64方式上传至数据库、希望对大家有所帮助、如果大家有任何疑问请给我留言、小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!