日期:2014-05-18  浏览次数:20806 次

jspsmart upload 接收 utf-8中文时乱码
jsp   以utf-8编码,当提交表单时,jspsmart   upload   接收到的中文是乱码,没辙了。

------解决方案--------------------

mySmartUpload.getRequest().getParameter( "参数名 ");

------解决方案--------------------
直接用request.getParametet()是取不出来值的,只能用mySmartUpload.getRequest().getParameter( "参数名 "),但这种方法取出的值都是乱码,和楼主碰到一样的问题,谁有更好的解决办法吗?


------解决方案--------------------
可以用sevlet处理,那样没问题的,实在不行就转码
------解决方案--------------------
加上 request.setCharacterEncoding("gbk");

最好是加一个过滤器

代码
public class EncodingFilter
implements Filter
{

public EncodingFilter()
{
pageEncoding = "gb2312";
}

public void setFilterConfig(FilterConfig filterConfig)
{
this.filterConfig = filterConfig;
}

public void init(FilterConfig config)
throws ServletException
{
filterConfig = config;
pageEncoding = config.getInitParameter("encoding");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest hrequest = (HttpServletRequest)request;
hrequest.setCharacterEncoding(pageEncoding);
chain.doFilter(request, response);
}

public void destroy()
{
filterConfig = null;
}

private String pageEncoding;
protected FilterConfig filterConfig;
}


web.xml中加上

<filter>
<filter-name>encoding</filter-name>
<filter-class>路径.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter> 
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>