zoukankan
html css js c++ java
struts tomcat 中文乱码解决
再也不用
strRet = new String(src.getBytes("ISO_8859_1"),"UTF-8");
配置下边
web.xml
<?
xml version="1.0" encoding="Shift_JIS"
?>
<!
DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"
>
<
web-app
>
<
filter
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
filter-class
>
htcommoninfo.SetCharacterEncodingFilter
</
filter-class
>
<
init-param
>
<
param-name
>
encoding
</
param-name
>
<
param-value
>
UTF-8
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>
enable
</
param-name
>
<
param-value
>
true
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
servlet-name
>
Action Servlet
</
servlet-name
>
</
filter-mapping
>
<
filter-mapping
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
servlet-name
>
Faces Servlet
</
servlet-name
>
</
filter-mapping
>
<
filter-mapping
>
<
filter-name
>
Set Character Encoding
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<
servlet
>
<
servlet-name
>
action
</
servlet-name
>
<
servlet-class
>
org.apache.struts.action.ActionServlet
</
servlet-class
>
<
init-param
>
<
param-name
>
config
</
param-name
>
<
param-value
>
/WEB-INF/struts-config.xml
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>
debug
</
param-name
>
<
param-value
>
2
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>
detail
</
param-name
>
<
param-value
>
2
</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
>
javaEncoding
</
param-name
>
<
param-value
>
GBK
</
param-value
>
</
init-param
>
<
load-on-startup
>
2
</
load-on-startup
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>
action
</
servlet-name
>
<
url-pattern
>
*.do
</
url-pattern
>
</
servlet-mapping
>
<
taglib
>
<
taglib-uri
>
/tags/struts-bean
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/struts-bean.tld
</
taglib-location
>
</
taglib
>
<
taglib
>
<
taglib-uri
>
/tags/struts-html
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/struts-html.tld
</
taglib-location
>
</
taglib
>
<
taglib
>
<
taglib-uri
>
/tags/struts-logic
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/struts-logic.tld
</
taglib-location
>
</
taglib
>
<
taglib
>
<
taglib-uri
>
/tags/struts-nested
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/struts-nested.tld
</
taglib-location
>
</
taglib
>
<
taglib
>
<
taglib-uri
>
/tags/struts-tiles
</
taglib-uri
>
<
taglib-location
>
/WEB-INF/struts-tiles.tld
</
taglib-location
>
</
taglib
>
<!--
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
-->
</
web-app
>
package
htcommoninfo;
import
javax.servlet.Filter;
import
javax.servlet.FilterConfig;
import
javax.servlet.ServletException;
import
javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse;
import
javax.servlet.FilterChain;
import
java.io.IOException;
public
class
SetCharacterEncodingFilter
implements
Filter
{
protected
FilterConfig filterConfig;
protected
String encodingName;
protected
boolean
enable;
public
SetCharacterEncodingFilter()
{
this
.encodingName
=
"
UTF-8
"
;
this
.enable
=
false
;
}
public
void
init(FilterConfig filterConfig)
throws
ServletException
{
this
.filterConfig
=
filterConfig;
loadConfigParams();
}
private
void
loadConfigParams()
{
//
encoding
this
.encodingName
=
this
.filterConfig.getInitParameter(
"
encoding
"
);
//
filter enable flag
String strIgnoreFlag
=
this
.filterConfig.getInitParameter(
"
enable
"
);
if
(strIgnoreFlag.equalsIgnoreCase(
"
true
"
))
{
this
.enable
=
true
;
}
else
{
this
.enable
=
false
;
}
}
public
void
doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws
IOException, ServletException
{
if
(
this
.enable)
{
request.setCharacterEncoding(
this
.encodingName);
}
chain.doFilter(request, response);
}
public
void
destroy()
{
}
}
查看全文
相关阅读:
C# winform 获取鼠标点击位置
C# 读取带有命名空间的xml
ImageUtility辅助类
C# 读取XML
C# 根据生日获取年龄
C# 将 WebService 封装成动态库
C# 生成条形码
C# Ftp Client 基本操作
C# SQL帮助类
C# 解压缩文件
原文地址:https://www.cnblogs.com/gwazy/p/1182971.html
最新文章
IView选择器Select开启搜索功能后动态赋值的坑
IView的select选择器输入框创建条目的问题
C#中List的ForEach和ForAll方法与foreach关键字的一点不同
Vue和原生Html简单实现淡入淡出动画效果
调用Axios出现"Cannot read property 'protocol' of undefined"的可能原因
C#Task中await和.Result和GetAwaiter().GetResult()方法的区别
亲手撸码,爬取 手机号码归属地最新数据(201911)
jquery省市区三级联动(数据来源国家统计局官网)内附源码下载
c#微信公众号开发一----基本设置,服务器配置token验证,获取timestamp/nonce/signature
微信公号分享样式。前端代码
热门文章
word转html预览
ORACLE 求和(多列)
mvc后台传到前台的值带html标签css(解决方法)
ef linq多表查询(三表)
邮箱图标的css样式
//某父元素(.class)底下相同class的第二的取值
oracle创建删除视图
mvc ajax跳转controller 的路径
使用AspectCore实现AOP模式的Redis缓存
ASP.NET Core 3.0 使用AspectCore-Framework实现AOP
Copyright © 2011-2022 走看看