1. 页面 这里输入代码
<div> <span id = "uploadimg" style = "margin: 50px; background-color: #ddd; affichage: en ligne de bloc; hauteur: 130px; largeur: 200px;"> <span style = "couleur: #bbb; Font-weight: 600; border: 2px #ccc Dished; Font-Size: 20px; Text-Align: Center; Affichage: Block en ligne; hauteur: 50px; largeur: 50px; Line-Height: 50px; Position: Absolut; margin-top: 40px; margin-left: 75px "Z-index: 99"> + </pan> <iMg id = "aperçu" Style = "Affichage: aucun;" style = "display: non" name = "imgcard" id = "imgfilebtn" id = "imgfilebtn" onchange = "javascrip
2. 后台
fichier privé imgcard; chaîne privée imgcardContentType; chaîne privée 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; casser; }} if ((imgcard.length () / 1024/1024)> 3) {return error;} bi = imageo.read (imgcard); ByteArrayOutputStream baos = new ByteArrayOutputStream (); ImageIo.write (BI, "JPG", Baos); octet [] bytes = baos.toByteArray (); String img = Encoder.EncodeBuffer (Bytes) .trim (); }以上所述是小编给大家介绍的 Struts2 中图片以 Base64 方式上传至数据库 , 希望对大家有所帮助 , 如果大家有任何疑问请给我留言 , 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!