一个简单的:
public String escapeHTMLTags( String input ) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if( input == null || input.length() == 0 ) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for( int i=0; i<input.length(); i++ ) {
ch = input.charAt(i);
if( ch == '<' ) {
buf.append( "<" );
}
else if( ch == '>' ) {
buf.append( "&rt;" );
}
else {
buf.append( ch );
}
}
return buf.toString();
}
public String escapeHTMLTags( String input ) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if( input == null || input.length() == 0 ) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for( int i=0; i<input.length(); i++ ) {
ch = input.charAt(i);
if( ch == '<' ) {
buf.append( "<" );
}
else if( ch == '>' ) {
buf.append( "&rt;" );
}
else {
buf.append( ch );
}
}
return buf.toString();
}
解决方案 »
- 客户端是用C/C++或其他语言编写的程序能调用服务端是用CXF发布的web service吗?
- 获取不到表单数据 java.lang.NullPointerException
- 关于MySQL处理乱码的问题(latin1_swedish_ci,IMPLICIT) and (gbk_chinese_ci,COERCIBLE)
- 关于graphviz 生成的SVG文件显示一行过长,不能折行的问题
- 关于JSP与javabean联系的路径问题
- 页面上的地址一般是填相对地址好还是绝对地址好
- 用SUBMIT提交,怎么去掉工具栏地址栏?
- import class 出错了
- 请问怎么才能得到可用分阿,我已经没分了
- 谁用过Resin3.0.0,请进
- 在XP版本中兼不兼容JSP服务器
- 不用Apache 又怎样!!我的Resin实在不能和Apache 配到一起
FUNCTION in java but is there is any thing equivalent
to Server.HTMLEncode in JSP.
int j=0;
int i=0;
int k=0;
String RETU="";
String temp=con;
int tagc=tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp=con.substring(j,i)+rep;
RETU+=temp;
i+=tagc;
j=i;
}
else{i+=1;
}
}
RETU+=con.substring(j);
return RETU;
}public String html(String s){
String re;
re=replace(s,"<","<");
re=replace(re,">",">");
re=replace(re,"\n","<br>");
re=replace(re," "," ");
re=replace(re,"'","'");
return re;
}