Not able to display special characters properly in a JSP page

前端 未结 2 1042
耶瑟儿~
耶瑟儿~ 2021-01-25 03:32

I need to display following special characters in a table TD (exclude the back slash in between < symbol and forward slash),

1) \'/<\\/@/tes

2条回答
  •  死守一世寂寞
    2021-01-25 04:03

    Everthing which get sent by JSP is by default treated as HTML by the webbrowser. The < indicates start of a HTML tag and thus the webbrowser will parse it as such (and eventually fail due to a syntax error).

    You want to escape those HTML special characters like <, >, & and ".

    < will be displayed as <
    > will be displayed as >
    & will be displayed as &
    " will be displayed as "
    

    If it is dynamic text, this is best to be done with JSTL tag.

    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ...
    
    

    Of if you want to set a HTML attribute, the JSTL fn:escapeXml() function is nicer.

    <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    ...
    
    

提交回复
热议问题