日期:2014-05-17 浏览次数:20777 次
String changFileName = new String(fileName.getBytes("UTF-8"),"ISO8859_1")
------解决方案--------------------
可以试一下楼上的方法,关于编码转换的,问题很多,有时服务器编码也会有影响
多试几种吧
------解决方案--------------------
将文件的路径,文件名,信息保存一份在数据库,然后重新以英文命名文件名
页面访问的时候,访问改变文件名的新的文件
------解决方案--------------------
增加一个过滤器:
import java.io.IOException; import java.net.URLDecoder; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; public class UrlFilter implements Filter { public final static String DEFAULT_URI_ENCODE = "UTF-8"; private FilterConfig config = null; private String encode = null; public void init(FilterConfig config) throws ServletException { this.config = config; this.encode = config.getInitParameter("DEFAULT_URI_ENCODE"); if(this.encode == null) { this.encode = DEFAULT_URI_ENCODE; } } public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String uri = request.getRequestURI(); String ch = URLDecoder.decode(uri, encode); if(uri.equals(ch)) { chain.doFilter(req, res); return; } ch = ch.substring(request.getContextPath().length()); config.getServletContext().getRequestDispatcher(ch).forward(req, res); } public void destroy() { config = null; } }
------解决方案--------------------