if(message.startsWith("<")
{
   处理或是转换
}
if(message.startsWith("/>")
{
   处理或是转换
}

解决方案 »

  1.   

    不好意思是:
    if(message.startsWith("<")
    {
       处理或是转换
    }
    if(message.endsWith("/>")
    {
       处理或是转换
    }
      

  2.   


    <%@ page import="java.text.SimpleDateFormat" %>
    if(message.startsWith("<")//将<转换为&lt
    {
             String makeContent=new String();
    StringTokenizer strToKen=new StringTokenizer(message,"<");
    while(strToKen.hasMoreTokens())
    {   
    makeContent=makeContent+strToKen.nextToken()+"&lt";

    }
    }
    if(message.endsWith("/>")  //将/>转换为/&gt
    {
              String makeContent=new String();
              StringTokenizer strToKen=new StringTokenizer(message,"/>");
              while(strToKen.hasMoreTokens())
    {   
    makeContent=makeContent+strToKen.nextToken()+"/&gt";

    }}
      

  3.   

    把"<" 和">" 转换一下就行了
      

  4.   

    我以前已经写过这样的方法了。
    再写一遍吧。
    楼上的不够灵活。
    你声明Replace 后可以自己随便定义方法了。
    <%
    方法一
    public static String toHtml(String s){
     s = Replace(s,"a","b");
     .............
     return s;
    }
     out.println(toHtml("aabbsd"));
    方法2
    public static String unHtml(String s){ 
    s = Replace(s,"\"","&quot;");
    s = Replace(s,">","&gt;");
    s = Replace(s,"<","&lt;");
    s = Replace(s,"\r\n","<br>"); 
    return s; 

    out.println(unHtml("asdfsaf.af>asfasfa<sfdsafas>asfasf>afsaf<"));
    %>
    <%!
    //声明Replace 
    public static String Replace(String source,String oldString,String newString) { 
    if(source == null) return null; 
    StringBuffer output = new StringBuffer(); 
    int lengOfsource = source.length(); 
    int lengOfold = oldString.length(); 
    int posStart = 0; 
    int pos; 
    while((pos = source.indexOf(oldString,posStart)) >= 0) { 
    output.append(source.substring(posStart,pos)); 
    output.append(newString); 
    posStart = pos + lengOfold; 

    if(posStart < lengOfsource) { 
    output.append(source.substring(posStart)); 

    return output.toString(); 

    %>
      

  5.   

    jdk1.4以上版本
    String s=request.getParameter("value");
    s=s.replaceAll("<","&lt;");
    s=s.replaceAll(">","&lt;");
    s=s.replaceAll(" ","&nbsp;");
    s=s.replaceAll("\\n","<br>");