国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Struts2中圖片以base64方式上傳至數(shù)據(jù)庫

2019-11-26 13:46:20
字體:
供稿:網(wǎng)友

1.頁面 這里輸入代碼

<div> <span id="uploadImg" style="margin:50px;background-color:#ddd;display:inline-block;height:130px;width:200px;"> <span style="color:#bbb;font-weight:600;border:2px #ccc dashed;font-size:20px;text-align:center;display:inline-block;height:50px;width:50px;line-height:50px;position:absolute;margin-top:40px;margin-left:75px;z-index:99">+</span> <img id="preview" style="display: none; "></span><input type="file" style="display:none" name="ImgCard" id="imgFileBtn" id="imgFileBtn" style="width:150px;" onchange="javascript:setImagePreview();"/> </div> 

2.后臺(tái)

private File 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; break; } } 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方式上傳至數(shù)據(jù)庫,希望對(duì)大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 榆中县| 杨浦区| 芜湖县| 宁武县| 汉中市| 福安市| 游戏| 凌源市| 上高县| 莱芜市| 浪卡子县| 汶上县| 宁陵县| 高阳县| 平凉市| 南充市| 永新县| 兴化市| 日土县| 兴义市| 阳原县| 安康市| 廊坊市| 晋中市| 牙克石市| 盐池县| 农安县| 黑河市| 喀喇沁旗| 津南区| 乐业县| 山东| 东乌珠穆沁旗| 柳河县| 锡林郭勒盟| 朝阳市| 湖南省| 河西区| 洛浦县| 且末县| 石首市|