首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jspsmart upload 接收 utf-8中文时乱码解决办法

2011-12-29 
jspsmart upload 接收 utf-8中文时乱码jsp以utf-8编码,当提交表单时,jspsmartupload接收到的中文是乱码,没

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>

热点排行