作为字符串检索的 JSP 标签不被执行
我有 Java 类,它负责渲染一些 html 元素,并且我们为它们创建了一些预定义的标签。
public class StartDateField {
private static StartDateField object;
private StartDateField(){}
public static StartDateField getInstance(){
if(object == null){
object = new StartDateField();
}
return object;
}
public String render(){
String field = "<field:text name='first_name' size='65' maxlen='63' style='field' />";
return field;
}
然后
我尝试在 JSP 标记内调用该渲染方法(该标记也导入到上面的类),
<td colspan="2">
<%=StartDateField.getInstance(SUBpagebean).render()%>
</td>
但它什么也不显示。当我查看源代码时,它显示返回的文本而不是执行标记。这是如何引起的以及如何解决?
I have Java class which is responsible for rendering some html elements and we have some predefined tags created for them.
public class StartDateField {
private static StartDateField object;
private StartDateField(){}
public static StartDateField getInstance(){
if(object == null){
object = new StartDateField();
}
return object;
}
public String render(){
String field = "<field:text name='first_name' size='65' maxlen='63' style='field' />";
return field;
}
}
Then I tried to call that render method inside the JSP tag (which also has import to above class)
<td colspan="2">
<%=StartDateField.getInstance(SUBpagebean).render()%>
</td>
But it displays nothing. When I go to view source it shows the returned text instead of executing the tag. How is this caused and how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<%= someExpression() %>
表示:计算 Java 表达式someExpression()
,并将其结果写入 HTTP 响应编写器。显然,您正在将
直接写入响应。JSP 标记必须位于要评估的 JSP 的静态源代码中。
请注意,JSTL 是标准标签库。
是自定义 JSP 标记。它不是 JSTL 标签。<%= someExpression() %>
means: evaluate the Java expressionsomeExpression()
, and write its result to the HTTP response writer. So obviously, you're writing<field:text name='first_name' size='65' maxlen='63' style='field' />
directly to the response.A JSP tag must be in the static source code of the JSP to be evaluated.
Note that JSTL is a standard library of tags.
<field:text>
is a custom JSP tag. It's not a JSTL tag.