用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);
}
}
&
相关文档:
我们都知道在jsp中include有两种形式,分别是
<%@ include file=” ”%>
<jsp:include page=” ” flush=”true”/>
前者是指令元素、后者是行为元素。具体它们将在何处用?如何用及它们有什么区别?这应该是很多人看 ......
表单如下:
<form name="form1" action="test.jsp" method="post" onsubmit="return checkData();">
<input name="checkall1" type="checkbox" value="0" onClick="checkAllBox(this);"/>全选<br>
<input name="answer" type="checkbox" value="a"/>A<b ......
1.
最基本的乱码问题。
这个乱码问题是最简单的乱码问题。一般新手会出现。就是
页面编码不一致导致的乱码。
<%@ page
language="java" pageEncoding="UTF-8"%>
<%@ page
contentType="text/html;charset=iso8859-1"%>
<html>
<head>
<title> ......
JS代码
<script
type="text/javascript">
function closewindow(){
window.returnValue = true;
window.close();
}
function clock(){
i = i -1;
if(document.getElementById("info")){
document.getElementById("info").innerHTML
......