gpt4 book ai didi

java - 如果字段是另一个类,则访问 jSTL 中类的字段

转载 作者:行者123 更新时间:2023-12-02 07:38:49 24 4
gpt4 key购买 nike

我有一个 bean 类:

public class Event{
private Customer customer
private String stringdate

public Event(){}

/*all getters and setters here*/
}

public class Customer{
private int custId
private String custname

public Customer(){}

/*all getters and setters here*/
}

有没有办法使用JSTL在jsp页面上显示内容?

编辑:eventsView 是从 servlet 传入的事件列表。当“cust”变量是 int 字段时,我可以显示它,但是当我将其更改为自定义类 Customer 时,我无法显示它,因为出现下面的异常。

<c:forEach items="${ eventsView }" var="events" varStatus="index">
<tr>
<td>${ index.count }</td>
<td>${ events.customer.custid }</td>
<td>${ events.stringdate }</td>

</tr>
</c:forEach>

谢谢

堆栈跟踪:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/CaspinolCustTest] threw exception [An exception occurred processing JSP page /event.jsp at line 32

29: <c:forEach items="${ eventsView }" var="events" varStatus="index">
30: <tr>
31: <td>${ index.count }</td>
32: <td>${ events.customer.custId }</td>
33: <td>${ events.stringdate }</td>

Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "customer"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.parseInt(Integer.java:514)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985)
at org.apache.jsp.event_jsp._jspx_meth_c_005fforEach_005f0(event_jsp.java:148)
at org.apache.jsp.event_jsp._jspService(event_jsp.java:100)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)

最佳答案

JSTL 使用公共(public) getter 方法。您需要公共(public)方法:Event 类中的 getCustomer()、getStringDate() 和 Customer 类中的 getCustId()。

关于java - 如果字段是另一个类,则访问 jSTL 中类的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11846970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com