用Servlet过滤器去除JSP页面中的乱码
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
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;
}
// filter的主体操作
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// 判断是否需要进行编码的设置
if (!ignore || request.getCharacterEncoding() == null) {
// 得到配置文件中的编码类型
String encoding = setEncoding(request);
if (encoding != null) {
request.setCharacterEncoding(encoding);
}
}
&
相关文档:
tomcat 默认使用的字符集是ISO-8859-1,不支持中文字符,所以在现实中文时需要转换字符和设置字符集。
server.mxl改为<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> ,添加代码转换字符String.getBytes("ISO-8859-1"),"UTF-8 ......
jsp中用javascript将中文Base64转码, Action中再用Base64解码
javascript中使用webtoolkit.base64.js,下载地址http://www.webtoolkit.info/djs/webtoolkit.base64.js
相关介绍 http://www.webtoolkit.info/javascript-base64.html
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/ ......
context.xml 文件夹中
<Context path="/wap"
docBase="D:\IDE\MyEclipse\wap\WebRoot" reloadable="false" >
request.getContextPath(); -==> /wap
this.getServletContext().getRealPath("") ;// D:\IDE\MyEclipse\wap\WebRoot
......
编写自定义标签步骤
编写标签处理器(处理标签的Java类),这些类需要实现一些规范化的标签接口
编写标签库描述文件(TLD),这个文件描述了每个标签和对应的Java标签处理器类之间的映射关系
在web.xml中配置标签库文件的URI
在JSP页面中利用taglib指令将标签库引入到页面中
......
1.ession内的存放的是对象的引用,所以修改内置对象后,不需要重新放置到session中
2.配置Context初始化参数
<Context-param>
<param-name></paran-name>
<param-value></param-value>
<Context-param>
this.getServletContext().getInitParameter(arg0);
--------------------- ......