开发者

use a simple tag in jsp page?

开发者 https://www.devze.com 2023-03-01 14:18 出处:网络
In my a.jsp file: <html> <body> <% out.print(\"<my:login error=\\\"${Error}\\\"/>\"); // It doesn\'t work :(

In my a.jsp file:

 <html>
 <body>
 <%
           out.print("<my:login error=\"${Error}\"/>"); // It doesn't work :(

 %>
           <my:login error="${Error}"/> // It only works if I put it here
 <开发者_StackOverflow/body>
 </html>

Can anybody tell me where I were wrong? Thanks.


In the first approach you're printing the tag as plain text and thus it becomes part of HTML directly. Truly it won't work since the webbrowser does not parse JSP tags. Using scriptlets is also discouraged anyway.

The second is the correct approach. If your sole functional requirement is to inline the tag conditionally, then nest it inside a JSTL <c:if> instead

<c:if test="${not empty Error}">
    <my:login error="${Error}"/>
</c:if>

or something.

0

精彩评论

暂无评论...
验证码 换一张
取 消