怎麼要使用页面中直接顯示HTML標記?HTMLFilter.filter(str)的用法
我在TOMCAT的servlet Example中看到這樣一個例子,我在表單的文本輸入模中輸入
<font color=red> 紅色的文字 </font> 然後提交,頁面上直接顯示: <font color=red> 紅色的文字 </font> ,我在想,頁面為什麼不执行font的HTML標記呢?為什麼不顯示紅色的“紅色的文字”呢?????
我看了看它頁面中的源文件,有 這個的代碼:HTMLFilter.filter(firstName)
你們知道這個東西嗎????我在例子中找不到這個東東的源文件, 有沒有人給我講講這個方面的知識呢??
以下是它的源代碼,可以在tomcat中運行的。。
Source Code for Request Parameter Example
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RequestParamExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType( "text/html ");
PrintWriter out = response.getWriter();
out.println( " <html> ");
out.println( " <head> ");
out.println( " <title> Request Parameters Example </title> ");
out.println( " </head> ");
out.println( " <body> ");
out.println( " <h3> Request Parameters Example </h3> ");
out.println( "Parameters in this request: <br> ");
if (firstName != null || lastName != null) {
out.println( "First Name: ");
out.println( " = " + HTMLFilter.filter(firstName) + " <br> ");
out.println( "Last Name: ");
out.println( " = " + HTMLFilter.filter(lastName));
} else {
out.println( "No Parameters, Please enter some ");
}
out.println( " <P> ");
out.print( " <form action=\ " ");
out.print( "RequestParamExample\ " ");
out.println( "method=POST> ");
out.println( "First Name: ");
out.println( " <input type=text size=20 name=firstname> ");
out.println( " <br> ");
out.println( "Last Name: ");
out.println( " <input type=text size=20 name=lastname> ");
out.println( " <br> ");
out.println( " <input type=submit> ");
out.println( " </form> ");
out.println( " </body> ");
out.println( " </html> ");
}
public void doPost(HttpServletRequest request, HttpServletResponse res)
throws IOException, ServletException
{
doGet(request, response);
}
}
[解决办法]
可能是第三方的东西吧,反正将字符转义即可