1. 页面 这里输入代码
<div> <span id = "uploadimg"style = "마진 : 50px; 배경색 : #ddd; 디스플레이 : 인라인-블록; 높이 : 130px; 너비 : 200px;"> <span style = "color : #bbb; font-weight : 600; 테두리 : 2px #ccc FONT-SIZE : 20PX; 텍스트-정렬 : 중심; 디스플레이 : 인라인-블록; 높이 : 50px; 너비 : 50px; 선-높이 : 50px; 위치 : 절대; 마진-탑 : 40px; 마진-왼쪽 : 75px; 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; 문자열 [] 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 = 새로운 BytearRayoutputStream (); imageio.write (bi, "jpg", baos); 바이트 [] bytes = baos.tobytearray (); 문자열 img = encoder.encodebuffer (bytes) .trim (); }以上所述是小编给大家介绍的 struts2 ut base64 方式上传至数据库 方式上传至数据库, 希望对大家有所帮助, 如果大家有任何疑问请给我留言, 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持! 小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!