I am new to spring MVC. I need to write java codes in a jsp(though its not a good practice, but i don't have other option). My Jsp is now like
<c:forEach items="${dbEntries}" var="c" varStatus="loop">
<tr>
<%
int i = 0;
system.out.println(i);
%>
<td rowspan="1">${c.getRh_name()}</td>
<td rowspan="1">${c.getIpm_name()}</td>`
</tr>
</c:forEach>
but its giving an error "org.apache.jasper.JasperException: Unable to compile class for JSP:". Can anyone help??
included headers are
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="spring"%>
<core:set var="contextPath" value="${pageContext.request.contextPath}"/>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
full exception stacktrace Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:490) org.apache.jasper.compiler.Compiler.compile(Compiler.java:379) org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:624) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Use jstl instead of java code inside jsp like this.
<td>${loop.count}</td>
will return you the count of iteration going on. Its likei+1
in for loopfor(int i=0;i<10;i++);