JSP标签c:forEach报错(二)
1、今天,我在用c标签写一些样例,结果出现一些错误,写下作为记录
具体错误如下:
三月 31, 2014 9:46:28 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [jsp] in context with path [/HighCharts] threw exception [Unable to compile class for JSP: An error occurred at line: 25 in the jsp file: /JSP/forEach.jsp List cannot be resolved to a type 22: <br /> 23: </c:forEach> 24: <% 25: List<String> list = new ArrayList<String>(); 26: list.add("You"); 27: list.add("Hai"); 28: list.add("Dong"); An error occurred at line: 25 in the jsp file: /JSP/forEach.jsp ArrayList cannot be resolved to a type 22: <br /> 23: </c:forEach> 24: <% 25: List<String> list = new ArrayList<String>(); 26: list.add("You"); 27: list.add("Hai"); 28: list.add("Dong"); Stacktrace:] with root cause org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 25 in the jsp file: /JSP/forEach.jsp List cannot be resolved to a type 22: <br /> 23: </c:forEach> 24: <% 25: List<String> list = new ArrayList<String>(); 26: list.add("You"); 27: list.add("Hai"); 28: list.add("Dong"); An error occurred at line: 25 in the jsp file: /JSP/forEach.jsp ArrayList cannot be resolved to a type 22: <br /> 23: </c:forEach> 24: <% 25: List<String> list = new ArrayList<String>(); 26: list.add("You"); 27: list.add("Hai"); 28: list.add("Dong"); Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) 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:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) 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:722)
2、错误原因
由于List是Java中的集合,是java.util.*包中的,因为没有导入这个Java包,导致出现这个错误
3、解决办法
在JSP顶部添加下面这句
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。