jsp乱码问题解决方法2
来源:互联网 发布:生存分析需要什么数据 编辑:程序博客网 时间:2024/05/16 10:12
2 . Servlet接收表单Request请求时乱码解决方法
第一种解决方法:
在request方法之前加入 request.setCharacterEncoding("GBK");
第二中解决方法:
在后台代码中加入过滤器,并在web.xml配置文件中进行相应的设置
public class SetCharacterEncodingFilter implements Filter
{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
在配置文件中添加如下代码
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在jsp页面把method设置为post 默认是get。设置好了method方法就不会出现乱码问题了
第
- jsp乱码问题解决方法2
- JSP乱码问题解决方法
- jsp乱码问题解决方法
- jsp乱码问题解决方法1
- jsp乱码问题解决方法3
- jsp中文乱码问题解决方法
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结(转)
- JSP中文乱码问题解决方法详解
- JSP中文乱码问题解决方法小结
- JSP字符中文乱码问题解决方法汇总
- JSP中文乱码问题解决方法小结
- JSP中文乱码问题解决方法小结
- 关于JSP中文乱码问题解决方法
- C#的Enum设计的相关指导在网上有相关文章论述:
- FreeMarker设计指南(完整整理)
- 模拟退火
- winform中C/S及asp.net中B/S的一般架构
- 网络工程师考试心得
- jsp乱码问题解决方法2
- C#编程:枚举(enum)与结构(struct)的定义和使用方法
- 《asp.net夜话》一书视频1-12章下载(2009年4月13日更新)
- 讲讲volatile的作用
- 网站文件管理器( Flash + ASP 架构)(原版)(ASP部分
- Visaul C#托盘程序制作心得
- 粗糙集
- 一本有意思的书:《基于嵌入式信号结构的嵌入式信号处理》
- 自适应控制