过滤器链实现中文转码和文字屏蔽功能
编写一个过滤器链实现如下功能:
1. 编写过滤器程序EncodingFilter,实现POST方式下的中文转码。
2. 编写过滤器程序liuyanfilter,实现将用户输入的用户名“张”转换成“李”,将用户输入的留言内容“剑桥”转换成“****”。
程序其他功能页面:
1. 编写liuyanform.jsp该页面用于完成表单的输入,其中包括:用户名、留言内容、提交按钮。
2. 编写liuyanservlet在该程序中的doPost()方法中使用请求转发的形式将程序跳转到liuyanresult.jsp
3. 编写liuyanresult.jsp程序,在该页面中输出用户提交的用户名及留言内容。
注:两个过滤器程序均对liuyanservlet程序进行过滤
[html]
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<html>
<head>
</head>
<body>
<form action="MessageServlet" method="post">
<table>
<tr>
<td>
标题:
<input type="text" name="title" size="30">
</td>
</tr>
<tr>
<td>
内容:
<textarea rows="5" cols="40" name="content"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
[html]
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<html>
<head>
</head>
<body>
用户名 :<%=request.getAttribute("title")%><br/>
留言信息:<%=request.getAttribute("content")%>
</body>
</html>
[html]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>CharacterFilter</filter-name>
<filter-class>com.mars.filter.CharacterFilter</filter-class>
</filter>
<filter>
<filter-name>WordFilter</filter-name>
<filter-class>com.mars.filter.WordFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterFilter</filter-name>
<url-pattern>/MessageServlet</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>WordFilter</filter-name>
<url-pattern>/MessageServlet</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>com.mars.servlet.MessageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MessageServlet</servlet-name>
<url-pattern>/MessageServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>submit.jsp</welcome-file>
</welcome-file-list>
</web-app>
[java]
package com.mars.filter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSer
补充:Web开发 , Jsp ,