Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
循环内jsp标记文件中的Access变量?_Jsp_File_Tags - Fatal编程技术网

循环内jsp标记文件中的Access变量?

循环内jsp标记文件中的Access变量?,jsp,file,tags,Jsp,File,Tags,我尝试创建一个jsp标记文件,它将调用一个helper类来打印输入对象。所以我创建了一个文件/WEB-INF/tags/formatter.tag <%@ tag import="package.Formatter"%> <%@ attribute name="value" required="true" type="java.lang.Object" %> <%=Formatter.format(pageContext.getAttri

我尝试创建一个jsp标记文件,它将调用一个helper类来打印输入对象。所以我创建了一个文件/WEB-INF/tags/formatter.tag

<%@ tag import="package.Formatter"%>
<%@ attribute name="value" required="true" type="java.lang.Object" %>              
<%=Formatter.format(pageContext.getAttribute("value"))%>

这样我就可以在JSP中调用它,如:

<t:formatter value="${obj}" />

但我发现它在循环中不起作用,例如

<c:forEach items="${list}" var="i">
   <t:formatter value="${i.property}"/>
</c:forEach>

我怀疑我不应该从
pageContext
获取属性。但我不确定。有人知道这一点吗?

试试以下方法:

首先,将格式化程序转换为标准JavaBean(即,使格式化方法非静态、没有参数构造函数等)。在中,将标记更改为:

<%@ tag import="package.Formatter" %>
<%@ attribute name="value" required="true" type="java.lang.Object" %> 
<jsp:useBean id="formatter" class="package.Formatter" />             
${formatter.format(value)}

${formatter.format(value)}

添加以下内容。您的问题很可能是“c”标记中没有任何内容得到处理

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


你说的“不工作”是什么意思?您得到了错误或错误的结果吗?websphere得到了一些ArrayIndexOutOfBoundException,由com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.getElexpressions引发。在我的例子中,我需要传递两个参数。e、 g.${formatter.format(值,2)}。这导致JSP错误:无法解析EL函数