1

I'm having tomcat 7 as server and using eclipse as IDE and using JSP and Java for my program.But when I run JSP Page ,my generated class for JSP is not complied ,the stackverflow trace is-

HTTP Status 500 - 


type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 433 in the generated java file
The code of method _jspx_meth_c_005fforEach_005f1(JspTag, PageContext, int[]) is exceeding the 65535 bytes limit

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Some code of my jsp page is

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="comparision_list.Comaprision"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="ref_time.Ref_log_current" %>
<html xmlns:ui="http://java.sun.com/jsf/facelets">
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Reference</title>
</head>
<body>
<jsp:useBean id="ref" class="comp_Mps.Comp_Mps_hs"/>

<br>

  <%
//Comaprision obj = new Comaprision();
   String s_date= request.getParameter("startdate");
   pageContext.setAttribute("s_date", s_date);
   String e_date= request.getParameter("enddate");
   pageContext.setAttribute("e_date", e_date);
   ref.refarray_vac1(s_date,e_date);
   ref.ClosestToMultiplesOfTen_User(s_date,e_date);

%>


<%
//Comaprision reference = new Comaprision();
   String ref_name= request.getParameter("ref_logtime");
   pageContext.setAttribute("ref_name", ref_name);
   ref.FindClosestToMultiplesOfTen(ref_name);
   ref.refernece(ref_name);

%>

<br><br><br>

 <table width = "170%" border = "1" cellspacing="0" cellpadding="0">
 <tr>
     <th>Date_Time</th>
     <th>beam_current</th>
     <th>beam_energy</th>
     <th>p21_readback</th>
     <th>p21_setvalue</th>
     <th>p21_vmeset</th>
     <th>p21_dacbyadc</th>
     <th>p22_readback</th>
     <th>p22_setvalue</th>
     <th>p22_vmeset</th>
     <th>p22_dacbyadc</th>
     <th>p23_readback</th>
     <th>p23_setvalue</th>
     <th>p23_vmeset</th>
     <th>p23_dacbyadc</th>
     <th>p24_readback</th>
     <th>p24_setvalue</th>
     <th>p24_vmeset</th>
     <th>p24_dacbyadc</th>
     <th>p22_readback</th>
     <th>p22_setvalue</th>
     <th>p22_vmeset</th>
     <th>p22_dacbyadc</th>
     <th>p26_readback</th>
     <th>p26_setvalue</th>
     <th>p26_vmeset</th>
     <th>p26_dacbyadc</th>
     <th>p27_readback</th>
     <th>p27_setvalue</th>
     <th>p27_vmeset</th>
     <th>p27_dacbyadc</th>
     <th>p28_readback</th>
     <th>p28_setvalue</th>
     <th>p28_vmeset</th>
     <th>p28_dacbyadc</th>
     <th>p29_readback</th
   </tr>


<c:set var="count" value="0" scope="page" />

<c:forEach var="row" items="${ref.refarray_vac1(param.startdate,param.enddate)}">
<c:forEach var="r" items="${ref.refernece(param.ref_logtime)}" begin="${count}" end="${count}"> 

<tr bgcolor="darkgray ">
<td><c:out value="${r.logtime}"></c:out></td>
<td>
<c:out value="${r.beam_current}"></c:out> </td>
<td>
<c:out value="${(r.beam_energy)}"/> 
</td>
<td>
<fmt:formatNumber value="${(r.p21_readback)}" maxFractionDigits="2" minIntegerDigits="2"  var="mm"></fmt:formatNumber>
<c:out value="${(r.p21_readback)}"/> 
</td>
<td>
<fmt:formatNumber value="${(r.p21_setvalue)}" maxFractionDigits="2" minIntegerDigits="2"  var="mm"></fmt:formatNumber>
<c:out value="${(mm)}"/> 
</td>
<td>
<fmt:formatNumber value="${(r.p21_vmeset)}" maxFractionDigits="2" minIntegerDigits="2"  var="mm"></fmt:formatNumber>
<c:out value="${(mm)}"/> 
-------- 

My jsp has 3207 lines of code an don 433 line I just had </td>

tiddi rastogi
  • 526
  • 3
  • 10
  • 33

2 Answers2

0

I had same problem with my views, according to this question the problem is:

JSPs get compiled into servlet code, which are then compiled into actual java .class files. JSP code will be put into one big doGet() method, and if your JSP file is really big, it will hit the method size limit of 65535. The limit is coming from JVM specification ("The value of the code_length item must be less than 65536").

Do a jsp:include for the HTML part(s) like proposed by McDowell.

WHAT WORKED FOR ME
After several attempts, (that worked but changed a bit my old functionallity), best sollutions I've found are 2:

  • create a min version of my finished components and scripts to save bytes of spaces. (like JQuery or js libraries)
  • Use loops/iterations instead of repeating code even when them mess your code readability

This question suggest to change:

<%@ include file="test.jsp" %>

To dynamic includes:

<jsp:include page="test.jsp" /> 

Also here describes a config workaround

Please note, that there is a configuration option in the JspServlet, "mappedfile".

If set to "false", adjacent println statements will be merged into a single one. See http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html#Configuration and the comments in conf/web.xml

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
0

The relevant part of the error is ... is exceeding the 65535 bytes limit. That means that your JSP is too large. 3207 line is indeed very large for a JSP.

Best practices recommend that the JSP should be only a view part. That means :

  • all business work or persistence should be dealt with in a servlet (or a controller is you are using a framework) ; the servlet puts relevant data in request attributes and forwards to the JSP that just displays them in HTML.
  • javascript, css, and other static ressources (images, etc.) should have their own files and should only be referenced in the JSP

If that is not enough (what means you really have complex pages) you should split the jsp in logical parts parts (for example tabs, or divs) and call them through <jsp:include ...> and not <%@ include ...%> ; the first generates different servlets with RequestDispatcher.include calls between them, the latter combines all in a single JSP file.

But IMHO you should really ask yourself why and how a single JSP comes up to 3207 lines and wonder whether your architecture is appropriate. It could be easier for later maintenance to split that in smaller files.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252