马光军--------BLOG

BlogJava 联系 聚合 管理
  1 Posts :: 25 Stories :: 5 Comments :: 0 Trackbacks
去除<、>特殊字符:
 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("<","&lt;");
15             out.println(str) ;
16             str=str.replace(">","&gt;");
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行的代码:效果如下
posted on 2008-12-02 22:21 马光军 阅读(48) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: