SetCharacterEncodingFilter jsp字符过滤器
package com.demo.filter;
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 = "GBK";
this.enable = false;
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
chain.doFilter(request, response);
}
public void destroy() {
}
}
————————————————————————————————————————————
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.
相关文档:
九大对象:
内置对象(又叫隐含对象,有9个内置对象):不需要预先声明就可以在脚本代码和表达式中随意使用
1-out:
javax.servlet.jsp.JspWriter类型,代表输出流的对象。作用域为page(页面执行期)
request:javax.servlet.ServletRequest的子类型,此对象封装了由WEB浏览器或其它客户端生成地HTTP
请求的细节 ......
jsp中读取properties文件,并把值设到js变量中:
web_stderr.properties文件内容:
common.username.error.null = UserName can not be null.
common.username.error.invalid = UserName is invalid.
common.password.error.null = Password can not bu null.
common.password.error.invalid = Password is invalid.
......
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%
//驱动程序名
String driverName="org.gjt.mm.mysql.Driver";
//数据库用户名
String userName="root";
//密码
S ......
1、 最基本的乱码问题。
这个乱码问题是最简单的乱码问题。一般新会出现。就是页面编码不一致导致的乱码。
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=iso8859-1"%>
<html>
<head>
<title>中文问题</title>
<meta http-equi ......