10-过滤输入字符串中的危险字符(字符串处理)

StringUtil.java

package com.lh.bean;

public class StringUtil {
	// 源字符串
	private String sourceStr;
	// 替换后的字符串
	private String targetStr;

	public String getSourceStr() {
		return sourceStr;
	}

	public void setSourceStr(String sourceStr) {
		this.sourceStr = sourceStr;
	}

	public String getTargetStr() {
		// 过滤字符&;‘〈〉/%=
		sourceStr = sourceStr.replaceAll("&", "&");
		sourceStr = sourceStr.replaceAll(";", ",");
		sourceStr = sourceStr.replaceAll("'", "");
		sourceStr = sourceStr.replaceAll("<", "<");
		sourceStr = sourceStr.replaceAll(">", ">");
		sourceStr = sourceStr.replaceAll("/", "");
		sourceStr = sourceStr.replaceAll("%", "");
		sourceStr = sourceStr.replaceAll("=", "");
		targetStr = sourceStr;
		return targetStr;
	}

	public void setTargetStr(String targetStr) {
		this.targetStr = targetStr;
	}

}


index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


index.jsp



	
请输入字符串:


 

filter.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


My JSP 'filter.jsp' starting page




	<%
		String sourceStr = request.getParameter("sourceStr");
	%>
	
	
	
	
	
过滤之前的字符串:
过滤之后的字符串:


10-过滤输入字符串中的危险字符(字符串处理)_第1张图片

你可能感兴趣的:(JavaBean技术)