filter(过滤不合法字符)(param)(textarea)(indexof("晕"))(form)

package com.javaweb;

import java.io.IOException;

import javax.management.modelmbean.RequiredModelMBean;
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 com.sun.net.httpserver.Filter.Chain;

public class FilterTest implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub
		System.out.println("销毁");
	}

	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest request=(HttpServletRequest)arg0;
		ServletResponse response=(ServletResponse)arg1;
		FilterChain chain=(FilterChain)arg2;
		request.setCharacterEncoding("gb2312");
		String charContent=request.getParameter("charContent");
		
		if(charContent!=null)
		{
			if(charContent.indexOf("晕")==-1)
			{
				chain.doFilter(request, response);
			}
			else
			{
				request.getRequestDispatcher("SendFailure.jsp").forward(request, response);
			}
		}
		else 
		{
			chain.doFilter(request, response);
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("初始化");

	}

}


CharForm.jsp

<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  
  <body>
    <form	action="ShowContent.jsp" method="post"> 
    	账号:<input type="text" name="username"/><br>
    	发信:<br>
    	<textarea name="charContent" rows="20" cols="40"></textarea><br>
    	<input type="submit" value="发送"/>
    	<input type="reset" value="重置"/>
    
    </form>
  </body>
</html>


SendFailure.jsp

<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  
  <body>
    <h1>发言失败</h1>
  </body>
</html>

ShowContent.jsp

<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>


  </head>
  
  <body>
    <center>
    	<h1>发言成功</h1>
    	账号:${param.username }<br>
    	内容:${param.charContent }<br>
    </center>
  </body>
</html>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值