过滤字符串中的危险字符

StringUtil7.java

public class StringUtil7 {
    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("=", "");
        targetStr=sourceStr;
        return targetStr;
    }
    public void setTargetStr(String targetStr) {
        this.targetStr = targetStr;
    }
    
}

index.jsp


    
请输入字符串:

result.jsp


    <%
        request.setCharacterEncoding("utf-8");
        String sourceStr= request.getParameter("sourceStr");
    %>
    
    
    
过滤之前的字符串:
过滤之后的字符串:
过滤字符串中的危险字符_第1张图片
17.PNG
20.PNG
19.PNG

你可能感兴趣的:(过滤字符串中的危险字符)