去除<、>特殊字符:
1 <%@ page language="java" pageEncoding="utf-8"%>
2 <html>
3 <head>
4 <title>My JSP 'index.jsp' starting page</title>
5 <meta http-equiv="pragma" content="no-cache">
6 <meta http-equiv="cache-control" content="no-cache">
7 <meta http-equiv="expires" content="0">
8 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
9 <meta http-equiv="description" content="This is my page">
10 </head>
11 <body>
12 <%
13 String str = "sd<df>" ;
14 str=str.replace("<","<");
15 out.println(str) ;
16 str=str.replace(">",">");
17 out.println(str) ;
18 str=str.replace("s","<font color=red>s</font>");
19 out.println(str) ;
20 %>
21 <font color=red></font>
22 </body>
23 </html>
24
显示结果:
如果去掉14行的代码:效果如下