我想列出所有国家/地区以获取所有相应的州和货币。
ConfFacade.java
public Result<List<Country>> listCountries() {
try {
String HQL = "SELECT DISTINCT o FROM Ocountry o LEFT JOIN FETCH o.ostate, o.ocurrency";
List<Country> list = em.createQuery(HQL).getResultList();
return new Result(Status.SUCCESS, list);
} catch(Exception e) {
e.printStackTrace();
return new Result<>(Status.ERROR, Exception.GENERAL, e.getMessage());
}
}
ConfFacadeLocal.java
public interface ConfFacadeLocal {
public Result<List<Country>> listCountries();
}
&#13;
这是我使用的 jsp 并对其进行编码:
listCountries.jsp
<%
try {
InitialContext ctx = new InitialContext();
ConfFacadeLocal confFacadeLocal = (ConfFacadeLocal)ctx.lookup("java:comp/env/tomin");
Result<List<Country>> result = confFacadeLocal.listCountries();
if(result.isUnsuccessful()) {
throw new Exception(result.getErrMsg());
}
List<Country> countryList = result.getObject();
if(countryList == null) {
throw new Exception("Error.");
}
out.print("OK");
%>
<table border="1" align="center" style="width:50%">
<thead>
<tr>
<th>country code</th>
<th>currency code</th>
<th>state id</th>
<th>state description</th>
</tr>
</thead>
<tbody><%
for (Ocountry country : countryList){ %>
<tr>
<td><%=country.getOccode()%></td>
<td><%=country.getOcurrency().getOcucode()%></td>
<td><%=country.getOstate().getOsid()%></td>
<td><%=country.getOstate().getOsdesc()%></td>
</tr><%
}
} catch (Exception e) {
e.printStackTrace();
out.print("Error: " + e.getMessage());
} %>
</tbody>
</table>
&#13;
这是我得到的错误:
cannot find symbol
symbol: method getOstate()
location: variable country of type com.ejb.entities.conf.Country
PWC6197: An error occurred at line: 42 in the jsp file: /country/listCountries.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: method getOstate()
location: variable country of type com.ejb.entities.conf.Country
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:129)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:299)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:392)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
&#13;
任何人都可以帮忙修复它吗?
答案 0 :(得分:0)
从您的 JSP 错误日志中,我猜您错过了向#listCountries
bean接口声明ConfFacadeLocal
方法。
向界面添加所需的方法声明应该可以解决问题:
public interface ConfFacadeLocal {
// other API methods ...
public Result<List<Country>> listCountries();
}
答案 1 :(得分:0)
那里(第41行):
<td><%=currency.getOcucode()%></td>
您正在使用尚未声明的货币变量。
看来货币是你程序中'Country'类的一个属性,所以也许你应该写一下
<td><%=country.getCurrency().getOcucode()%></td>
'state'变量存在同样的问题。