jsp页面中
String s="<h1>This is a heading</h1>"
out.println(s);
输出的是:this is a heading而不是<h1>This is a heading</h1>,怎么让它<h1>This is a heading</h1>????

解决方案 »

  1.   

    replaceAll????含有其他代码时就不好使啊
      

  2.   

    String sanitizing(String string) {
            string = string.replaceAll("&", "&amp;");
            string = string.replaceAll("<", "&lt;");
            string = string.replaceAll(">", "&gt;");
            string = string.replaceAll("\"", "&quot;");
            string = string.replaceAll("'", "&#39;");        return string;
    }
      

  3.   

    输出的是 this is a heading 啊
      

  4.   

    去除THML格式,去除格式方法可以在网上找下
      

  5.   

    out.println("<</<>h1>"+"1111"+"<</<>/h1>");
     应该可以,我试过了
      

  6.   


    out.println("<</<>h1>1111<</<>/h1>");
      

  7.   


    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <html>
      <head>
      </head>
      <%
      String s="<</<>h1>This is a heading<</<>/h1>";
      %>
      <body>
        <%=s %>
      </body>
    </html>
      

  8.   

    输出的是字符串,而html代码不是字符串
      

  9.   

    用标签吧,struts1或这struts2都行,struts1写法是,<c:out value="${a}" escapeXml="true"/>
    struts2的话:<s:property value="b" escape="true"/> 。前提是你把要输出的东西扔request里了
      

  10.   

    strut没试过,,但是六楼的方法可行,谢谢大家的参与