今天碰到了個比較奇怪的問題,居然是因?yàn)镴SP太大導(dǎo)致文件編譯不了,上網(wǎng)查了一下,把解決方法貼下來,以供以后參考:
The problem is that there is a limit on the size of a compiled method in a
Java class file, and that limit is what we're running up against. Recall
that a JSP page is compiled into a servlet, and into essentially only one
method in that servlet. Hence, if your page contains many, many tags, that
method becomes too big, and up comes the exception that you're seeing.
There are a couple of (partial) solutions.
1) Break your giant page up into multiple smaller pages and bring them
together at run time using <jsp:include>. Note that <%@include> won't work,
because that's a compile-time include, which will get you straight back to
the original problem.
2) Look for places to save on tags. For example, the <html:option> tag was
recently extended to allow the specification of the text to display, so
that you can replace this:
<html:option ... ><bean:message key="foo"/></html:option>
with this:
<html:option ... key="foo"/>
More info pls access this link: Solution
我就是用了第一種方法解決的,之前include JSP的時候用了%@include , 后來用了<jsp:include>就不會用問題了.順便貼一下兩者的區(qū)別:
@include & jsp:include的區(qū)別
引用:http://www.ibm.com/developerworks/cn/java/j-jsp04293/
本文是 Java Brett McLaughlin 繼第一篇 JSP 最佳實(shí)踐文章后的后續(xù)文章,在文中,作者向您演示了如何擴(kuò)展 JSP 技術(shù)中用于動態(tài)內(nèi)容的包含功能。了解靜態(tài) include 偽指令和動態(tài) jsp:include 元素之間的差異,搞清楚如何混合搭配這二者以獲取最優(yōu)性能。
在新的 JSP 最佳實(shí)踐系列的前一篇文章中,您了解了如何使用 JSP include 偽指令將諸如頁眉、頁腳和導(dǎo)航組件之類的靜態(tài)內(nèi)容包含到 Web 頁面中。和服務(wù)器端包含一樣,JSP include 偽指令允許某個頁面從另一個頁面提取內(nèi)容或數(shù)據(jù)。
清單 1. JSP include 偽指令
<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>newInstance.com</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<link href="/styles/default.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="header.jsp" %>
<%@ include file="navigation.jsp" %>
<%@ include file="bookshelf.jsp" %>
<%@ include file="/mt-blogs/index.jsp" %>
<%@ include file="footer.jsp" %>
</body>
</html>
雖然 include 非常適于將靜態(tài)內(nèi)容并入 Web 頁面,但對于動態(tài)內(nèi)容卻不盡如人意。我們在前一篇文章中在試圖重新裝入高速緩存文件時發(fā)現(xiàn)了這一問題。與大多數(shù)頁眉文件及頁腳文件不同,動態(tài)內(nèi)容變化頻繁,必須時刻更新。我們將首先扼要地重述一下 include 偽指令的局限性,然后我將向您演示如何用 jsp:include 標(biāo)記來擴(kuò)展 JSP 的包含能力。
高速緩存問題
JSP include 偽指令的不足之處有一個是:它會導(dǎo)致 Web 瀏覽器高速緩存所有頁面。在處理諸如頁腳、版權(quán)聲明或一組靜態(tài)鏈接之類的靜態(tài)組件時,這是有意義的。這些文件不會改變,因此沒有理由讓 JSP 解釋器不斷地重新輪詢其中的數(shù)據(jù)。凡是可能的地方,都應(yīng)該實(shí)現(xiàn)高速緩存,因?yàn)樗纳屏藨?yīng)用程序的性能。
但是,有時侯,進(jìn)行高速緩存會得不償失。如果提入的內(nèi)容來自使用動態(tài)數(shù)據(jù)(如 Weblog 或數(shù)據(jù)庫驅(qū)動的 JSP 文件)的程序,甚至如果所包含的內(nèi)容是經(jīng)常變化的 HTML(如時間戳記),那么每當(dāng)裝入 Web 頁面時,都需要顯示這些文件或程序的最新版本。遺憾的是,JSP include 偽指令并不具備這一功能。在測試和開發(fā)周期中,在瀏覽器中禁用高速緩存通常能夠解決這一問題。但是,對于實(shí)際使用的應(yīng)用程序而言,性能是任何設(shè)計決策過程中的一項(xiàng)重要因素,禁用高速緩存并不是一種可行的長遠(yuǎn)之計。更好的解決方案是使用 jsp:include 標(biāo)記。
jsp:include 標(biāo)記
jsp:include 只不過是一個不同于 include 的偽指令而已。 jsp:include 的優(yōu)點(diǎn)在于:它 總是會檢查所含文件中的變化。過一會兒我們將研究這一新標(biāo)記的工作方式。但首先看一下兩種 include 各自的代碼,以便能夠看到二者之間的異同。
清單 2 顯示了一個簡單頁面,它使用了原始的 JSP include 偽指令。
清單 2. JSP include 偽指令
<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>JSP include element test</title>
</head>
<body>
This content is statically in the main JSP file.<br />
<%@ include file="included.html" %>
</body>
</html>
清單 3 是同一個頁面,只不過這里轉(zhuǎn)成使用 jsp:include 標(biāo)記。
清單 3. 轉(zhuǎn)成使用 jsp:include
<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>JSP include element test</title>
</head>
<body>
This content is statically in the main JSP file.<br />
<jsp:include page="included.html" flush="true" />
</body>
</html>
您應(yīng)該注意這兩種代碼類型之間的兩大區(qū)別。首先, jsp:include 元素不使用屬于 include 偽指令的 %@ 語法。實(shí)際上, jsp 前綴讓 JSP 編譯器知道:它應(yīng)該尋找標(biāo)準(zhǔn) JSP 標(biāo)記集中的元素。其次,指定要包含的文件的屬性從 file 變成了 page 。
flush 屬性
您可能已注意到 jsp:include 代碼示例中的 flush 屬性。顧名思義, flush 指示在讀入包含內(nèi)容之前是否清空任何現(xiàn)有的緩沖區(qū)。JSP 1.1 中需要 flush 屬性,因此,如果代碼中不用它,會得到一個錯誤。但是,在 JSP 1.2 中, flush 屬性缺省為 false。由于清空大多數(shù)時候不是一個重要的問題,因此,我的建議是:對于 JSP 1.1,將 flush 設(shè)置為 true;而對于 JSP 1.2 及更高版本,將其設(shè)置為關(guān)閉。
jsp:include 是如何工作的
如果您有點(diǎn)愛刨根問底,那么可能十分想知道 jsp:include 標(biāo)記的行為為什么與 include 偽指令不同。道理其實(shí)十分簡單: jsp:include 包含的是所包含 URI 的 響應(yīng),而不是 URI 本身。這意味著:對所指出的 URI 進(jìn)行 解釋,因而包含的是 生成的響應(yīng)。如果頁面是 HTML,那么將得到一點(diǎn)也沒有變化的 HTML。但是,如果是 Perl 腳本、Java servlet 或者 CGI 程序,那么得到的將是從該程序解釋而得的結(jié)果。雖然頁面通常就是 HTML,但實(shí)際程序恰好是達(dá)到目的的手段。而且,由于每次請求頁面的時候都會進(jìn)行解釋,因此從來不會象使用 include 偽指令時那樣高速緩存結(jié)果。雖然這只是很小的變動,但它卻導(dǎo)致了您所見到的行為中的全部差異。
一種混合搭配的解決方案
include 偽指令在某些網(wǎng)站上有其用武之地。例如,如果站點(diǎn)包含一些(如果有變化,也很少)幾乎沒有變化的頁眉、頁腳和導(dǎo)航文件,那么基本的 include 偽指令是這些組件的最佳選項(xiàng)。由于 include 偽指令采用了高速緩存,因此只需放入包含文件一次,其內(nèi)容就會被高速緩存,其結(jié)果會是極大地提高了站點(diǎn)的性能。
然而,對于現(xiàn)在許多 Web 應(yīng)用程序或站點(diǎn)而言,地毯式的高速緩存并不能解決問題。雖然頁眉和頁腳可能是靜態(tài)的,但是不可能整個站點(diǎn)都是靜態(tài)的。例如,從數(shù)據(jù)庫提取導(dǎo)航鏈接是很常見的,并且許多基于 JSP 技術(shù)的站點(diǎn)還從其它站點(diǎn)或應(yīng)用程序上的動態(tài) JSP 頁面提取內(nèi)容。如果正在處理動態(tài)內(nèi)容,那么需要采用 jsp:include 來處理該內(nèi)容。
當(dāng)然,最好的解決方案是經(jīng)常把這兩種方法混合搭配使用,將每種構(gòu)造用到最恰當(dāng)?shù)牡胤健G鍐?4 是混合搭配包含解決方案的一個示例。
清單 4. 混合搭配解決方案
<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>newInstance.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<jsp:include page="header.jsp" flush="true">
<jsp:param name="pageTitle" value="newInstance.com"/>
<jsp:param name="pageSlogan" value=" " />
</jsp:include>
<%@ include file="/navigation.jsp" %>
<jsp:include page="bookshelf.jsp" flush="true" />
<jsp:include page="/mt-blogs/index.jsp" flush="true" />
<%@ include file="/footer.jsp" %>
</body>
</html>
上面的代碼顯示了前一篇文章中的示例索引頁面。導(dǎo)航鏈接和頁腳是靜態(tài)內(nèi)容,一年最多更改一次。對于這些文件,我使用了 include 偽指令。內(nèi)容窗格包含 Weblog 和“bookshelf”組件,它們是動態(tài)生成的。這兩個組件需要一直更新,因此對它們,我使用了 jsp:include 標(biāo)記。 header.jsp 文件有點(diǎn)奇怪。這個組件是從另一個本質(zhì)上是靜態(tài)的 JSP 頁面提取的。但是,正如您將注意到的那樣,它從包含頁提取頁“標(biāo)語”,然后將它顯示出來。要處理這一共享信息,我們必須向頁眉文件傳入?yún)?shù)。而要處理那些參數(shù),就必須使用 jsp:include 元素。
后記:網(wǎng)上還有一種Solution:
try giving this in the deployment descriptor.
< jsp - param >
< param - name > noTryBlocks </ param - name >
< param - value > true </ param - value >
</ jsp - param >
本人沒有試過, 不知好不好用....