导入图片中文乱码解决方式

- 问题描述:
导入图片乱码,数据库保存的图片name为乱码,web页面图片显示不出来,并且文件名字为乱码
- 解决方式:
配置tomcat/conf/server.xml文件
配置一下URLEncoding的编码为UTP-8

    <Connector executor="tomcatThreadPool" acceptCount="1000" port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" maxHttpHeaderSize ="3145728" URIEncoding="UTF-8"/>
    <Connector port="8809" protocol="AJP/1.3" redirectPort="8443" />
发布了79 篇原创文章 · 获赞 4 · 访问量 1万+
展开阅读全文

获取的图片地址乱码解决,但是保存的图片乱码怎么解决?在线等,求大神,解决,速结贴

07-29

package com.togest.emis.modules.resource.web; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.togest.emis.framework.utils.EncodeUtils; /** * * * @author mmk * */ @Controller public class PsaveController { @RequestMapping(value="save",method = RequestMethod.POST) public void save(Map<String,Object> map,HttpServletRequest request,HttpServletResponse response) throws IOException{ String imageData2 = request.getParameter("imageData2"); String file_path = request.getParameter("file_path"); file_path = URLDecoder.decode(file_path , "utf-8"); System.out.println("++++++++++++++++"+file_path); //String f = new String(request.getParameter("file_path").getBytes("ISO-8859-1"),"UTF-8"); //System.out.println("+++++++++++++++++"+f); String file_name = request.getParameter("file_name"); String Path = request.getSession().getServletContext().getRealPath("/"); String filePath2 = file_path.substring(0, 34); String filePath=file_path.replace(filePath2,Path); filePath =EncodeUtils.isoDecode(filePath); String fileName=file_name; File file = new File(filePath); System.out.println("+++++++"+filePath); //System.out.println("+++++++++"+EncodeUtils.isoDecode(filePath)); if(imageData2!=null){ try{ FileOutputStream write = new FileOutputStream(file); byte[] decoderBytes = Base64.decodeBase64(imageData2.replace("data:image/png;base64,","")); imageData2 = imageData2.replace("base64,",""); write.write(decoderBytes); write.flush(); write.close(); }catch(Exception e){ e.printStackTrace(); } } } } 保存控制器代码 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/common/taglibs.jsp"%> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> <!-- jQuery --> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery.ui.core.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery.ui.widget.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery.ui.mouse.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery.ui.draggable.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/jquery.base64.js"></script> <!-- wColorPicker --> <link rel="Stylesheet" type="text/css" href="${pageContext.request.contextPath}/system/css/wColorPicker.css" /> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/wColorPicker.js"></script> <!-- wPaint --> <link rel="Stylesheet" type="text/css" href="${pageContext.request.contextPath}/system/css/wPaint.css" /> <script type="text/javascript" src="${pageContext.request.contextPath}/system/js/wPaint.js"></script> </head> <body> <!-- <img id="canvasImage3" onload="DrawImage(this)" style="display:none" src="${requestScope.filePath}" name="${requestScope.fileName}" />--> <img id="canvasImage3" onload="DrawImage(this)" style="display:none" /> <table id="full"> <tr> <td> <div id="wPaint2" style="position:relative; width:1620px;height:1200px;background:#CACACA; border:solid black 1px;"> </div> </td> <!-- <td><img id="canvasImage2" src=""/></td>--> </tr> <tr> <td colspan="2"> <div> <div id="box"></div> <input type="button" value="保存" onClick="saveImage2()" onblur="saveImage2()" /> <input type="button" value="提交" onblur="saveImage2()" onclick="saveImage2()"> <input type="button" value="全屏" onclick="full_screen()"> </div> <br /> </td> </tr> </table> <br /> <br /> <script type="text/javascript"> $(document).ready(function() { //alert('${filePath}'); ///alert('${ctx}/fileupload/download_file_url?fileDir=${filePath}'); $('#canvasImage3').attr('src','${ctx}/fileupload/download_file_url?fileDir=${filePath}'); }); function saveImage2() { var imageData2 = $("#wPaint2").wPaint("image");//获取wPaint的image属性值可获取base64格式的图片数据 var file_path = encodeURI(document.getElementById("canvasImage3").src);//这个获取乱码 file_path = encodeURI(file_path); var file_name = document.getElementById("canvasImage3").name; alert(file_path); $.ajax({ url : '${ctx}/save', type : 'post', data : { imageData2 : imageData2, file_path : file_path, file_name : file_name }, dataType : "json", success : function(result) { alert(result); if ("ture" == $.trim(result)) { $("#box").html("保存成功"); } else { $("#box").html("保存失败"); } }, error : function() { $("#box").html("保存成功"); } }); //$("#canvasImage2").attr('src', imageData2); } function convertCanvasToImage(canvas) { var image = new Image(); image.src = canvas.toDataURL("image/png"); return image; } var flag = false; //控制小图 function DrawImage(ImgD) { var image = new Image(); image.src = ImgD.src; if (image.width > 1620 || image.height > 1200) { image.width = 1620; image.height = 1200; } $("#wPaint2").css({ width : image.width, height : image.height }); $("#wPaint2").wPaint({ menuOrientation : 'vertical', imageBg : image.src }); } function full_screen() { var full = document.getElementById("full"); requestFullScreen(full); } function requestFullScreen(element) { var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen; if (requestMethod) { requestMethod.call(element); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } } </script> </body> </html> 编辑页面如下 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览