use a simple tag in jsp page?
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.
精彩评论