jstl 问题:2 最后一个要从我的 jsp 中删除的 scriptlet
我使用的代码工作正常,但这是我的 jsp 中的最后一个 scriptlet:
<% List listMillesime= MultiMillesimeFactory.getInstance().getListMillesimeActif();
pageContext.setAttribute("listMillesime",listMillesime);
%>
...
<c:forEach var="millesime" items="${listMillesime}">
...
</c:forEach>
这是工厂声明:
public class MultiMillesimeFactory {
private static MultiMillesime multiMillesime;
private MultiMillesimeFactory(){
}
public static MultiMillesime getInstance() {
if (multiMillesime == null) {
multiMillesime = new MultiMillesime();
}
return multiMillesime;
}
}
Multimillesime 是一个标准类,其方法 getListMillesimeActif
返回一个列表。声明:
public class MultiMillesime {
...
public List getListMillesimeActif() throws Exception {
List _l = Collections.synchronizedList(new LinkedList());
...
return _l;
}
}
c:foreach在列表和枚举上工作正常,但这里的问题来自于getInstance的使用,我尝试过MultiMillesimeFactory.Instance.ListMillesimeActif但没有成功。
最后一个脚本是:
<a href='<%=request.getContextPath() %>
我不确定这两个都是可移动的。
I use a code that works fine but here's the last scriptlets in my jsp :
<% List listMillesime= MultiMillesimeFactory.getInstance().getListMillesimeActif();
pageContext.setAttribute("listMillesime",listMillesime);
%>
...
<c:forEach var="millesime" items="${listMillesime}">
...
</c:forEach>
Here is the factory declaration :
public class MultiMillesimeFactory {
private static MultiMillesime multiMillesime;
private MultiMillesimeFactory(){
}
public static MultiMillesime getInstance() {
if (multiMillesime == null) {
multiMillesime = new MultiMillesime();
}
return multiMillesime;
}
}
Multimillesime is a standard class with a method getListMillesimeActif
returning a list. Declaration :
public class MultiMillesime {
...
public List getListMillesimeActif() throws Exception {
List _l = Collections.synchronizedList(new LinkedList());
...
return _l;
}
}
c:for each works fine on list and enum but here the problem comes from the use of the getInstance, I've tried MultiMillesimeFactory.Instance.ListMillesimeActif without success.
And the last scriptlet is :
<a href='<%=request.getContextPath() %>
I'm not sure that both of these are removable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
<%=request.getContextPath() %>
scriptlet 替换为 JSTL 标记:并不罕见:
看到这样的内容 MultiMillesimeFactory:看起来这是您代码库中的一个类,我们无法神奇地为您调试该问题。听起来不像是 JSP 问题。
“尝试 MultiMillesimeFactory.Instance.ListMillesimeActif 但没有成功”是什么意思?
编辑:回复:您的评论:我不确定我明白您的意思,但我猜问题是您需要使用
MultiMillesimeFactory 正确查找它。但是,您确实应该尽可能避免使用 scriptlet。相反,使用适当的 servlet 将
ListMillesimeActif
注入到请求中,如下所示:You can replace the
<%=request.getContextPath() %>
scriptlet with a JSTL tag:It is not uncommon to see something like this, either:
As for the issue with the
MultiMillesimeFactory
: it looks like that's a class in your codebase, and we can't magically debug that issue for you. It doesn't sound like a JSP problem.What does "tried MultiMillesimeFactory.Instance.ListMillesimeActif without success" mean?
Edit: re: your comment: I'm not sure I understand what you mean, but I'd guess the problem is that you need to use the fully qualified class name of
MultiMillesimeFactory
to look it up properly. However, you really should avoid using scriptlets as much as possible. Instead, use a proper servlet to inject theListMillesimeActif
into the request, like this: