浏览 3346 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-09-27
com.opensymphony.webwork.dispatcher.multipart.JakartaMultiPartRequest里面有一个名叫public JakartaMultiPartRequest(HttpServletRequest servletRequest, String saveDir, int maxSize) throws IOException 这个方法出了问题!原因如下,它在调用DiskFileUpload组件的时候,没有设置其编码,按照惯例,如不设置编码即为系统编码,因为我的系统编码是gbk,很显然地与utf-8出现了冲突.怎么办?改掉它. /** * Multipart form data request adapter for Jakarta's file upload package. * * @author Bruce Ritchie */ public class JakartaMultiPartRequest extends MultiPartRequest { //~ Instance fields //////////////////////////////////////////////////////// // maps parameter name -> List of FileItem objects private Map files = new HashMap(); // maps parameter name -> List of param values private Map params = new HashMap(); //~ Constructors /////////////////////////////////////////////////////////// /** * Creates a new request wrapper to handle multi-part data using methods adapted from Jason Pell's * multipart classes (see class description). * * @param maxSize maximum size post allowed * @param saveDir the directory to save off the file * @param servletRequest the request containing the multipart */ public JakartaMultiPartRequest(HttpServletRequest servletRequest, String saveDir, int maxSize) throws IOException { DiskFileUpload upload = new DiskFileUpload(); // we must store all uploads on disk because the ww multipart API is missing streaming // capabilities upload.setSizeThreshold(0); upload.setSizeMax(maxSize); //以下是我加的 String charset = servletRequest.getCharacterEncoding(); if (charset != null) { upload.setHeaderEncoding(charset); } //以上是我加的 if (saveDir != null) { upload.setRepositoryPath(saveDir); } // Parse the request try { List items = upload.parseRequest(servletRequest); for (int i = 0; i < items.size(); i++) { FileItem item = (FileItem) items.get(i); log.debug("Found item " + item.getFieldName()); if (item.isFormField()) { log.debug("Item is a normal form field"); List values = null; if (params.get(item.getFieldName()) != null) { values = (List) params.get(item.getFieldName()); } else { values = new ArrayList(); } // note: see http://jira.opensymphony.com/browse/WW-633<wbr></wbr> // basically, in some cases the charset may be null, so // we're just going to try to "other" method (no idea if this // will work) //将下面这句话提前. //String charset = servletRequest.getCharacterEncoding(); if (charset != null) { values.add(item.getString(charset)); } else { values.add(item.getString()); } params.put(item.getFieldName(), values); } else if (item.getSize() == 0) { log.debug("Item is a file upload of 0 size, ignoring"); } else { log.debug("Item is a file upload"); List values = null; if (files.get(item.getFieldName()) != null) { values = (List) files.get(item.getFieldName()); } else { values = new ArrayList(); } values.add(item); files.put(item.getFieldName(), values); } } } catch (FileUploadException e) { log.error(e); } } 经过以上修改,然后再到web.xml里面配置一个SetCharacterEncoding的过滤器并设置其编码为UTF-8就OK了... 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-09-28
webwork2.2.4以后已经解决了乱码问题
|
|
返回顶楼 | |