java - 无法编译 JSP :An error occurred at line: 433 in the generated java file 的类

标签 java eclipse jsp tomcat7

我使用 tomcat 7 作为服务器,使用 eclipse 作为 IDE,并在我的程序中使用 JSP 和 Java。但是当我运行 JSP Page 时,我为 JSP 生成的类未编译,stackverflow 跟踪是-

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)

我的jsp页面的一些代码是

<!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)}"/> 
-------- 

我的jsp有3207行代码,我刚刚有433行</td>

最佳答案

根据this question,我的观点也有同样的问题。问题是:

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.

什么对我有用
经过多次尝试(有效但改变了我的旧功能),我发现的最佳解决方案是 2:

  • 创建我已完成的组件和脚本的最小版本以节省字节空间。 (如 JQuery 或 js 库)
  • 使用循环/迭代而不是重复代码,即使它们会扰乱代码的可读性

This question建议更改:

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

动态包括:

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

还有here描述了配置解决方法

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

关于java - 无法编译 JSP :An error occurred at line: 433 in the generated java file 的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29533774/

相关文章:

java - 构建失败[错误] 15669

Java Servlet 请求参数为空

java - 如何在jsp中获取img标签中的blob图像

mysql - 在 Tomcat 服务器上使用 mySQL?

java - 显示 HashMap 时出现问题

java - 在火星 Eclipse 中安装失败的 Flex 构建器

java - 在 Kotlin 函数类型中表达 "super"泛型?

java - 按名称获取 ArrayList<NameValuePair> 值

eclipse - 在 Eclipse 中找不到 Nexus 7 的存储/模拟/0/文件夹

c++ - 未通过路径变量识别 MinGW