ちょっとした裏話:
非常に大きくなったファイルで作業しているため、最終的に次のエラーが発生します。
The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit.
これを回避するために、jsp:include
タグを利用してファイルを「モジュール化」しています。jsp:param
オブジェクトをシリアライズし、タグを使用して jsp:include ファイルでデシリアライズすることにより、メイン ファイルからインクルード ファイルにオブジェクトを渡すことができました。ただし、これらのオブジェクトは、メイン ファイルと複数のインクルード ファイルで使用、変更、再利用、再変更されているかのように扱われます。インクルードファイルをレンダリングした後にオブジェクトをメインファイルに戻す方法があるかどうか、または参照によってこれらのオブジェクトにアクセスして、1つのインクルードファイルとその適切なインスタンス内で変更できるようにする方法があるかどうか疑問に思っています変更されたオブジェクトは、その下にある他のインクルード ファイルを再利用できますか?
これまでのところpagecontext.setAttribute()
、(参照によるものではないようで、メインファイルに変更された後に値を戻すことができないようです)およびjsp:param
(とほぼ同じ)を検討しましたpagecontext.setAttribute()
。
これは私がこれまでに持っているものです:
以下のコード サンプル: (これで誰も混乱しないことを願っています。構文の修正を探しているわけではありません。参照によって同じオブジェクトにアクセスできるようにするソリューションを探しているだけです (グローバル変数とインクルード タグ) またはオブジェクトを main.jsp に戻して、変更後に次の jsp:include がアクセスできるようにします。
メイン.jsp
//Serialized Objects, Google Gson object
Gson gson = new Gson();
String serializedObject = gson.toJson( objectName );
<jsp:include page="/includes/includedFileName1.jsp">
<jsp:param name="serializedObject" value="<%= serializedObject %>" />
</jsp:include>
<!-- Is there a way to ensure includedFileName2 .jsp gets the modified version of object from includedFileName1.jsp? -->
<jsp:include page="/includes/includedFileName2.jsp">
<jsp:param name="serializedObject" value="<%= serializedObject %>" />
</jsp:include>
<!-- Is there a way to ensure includedFileName3 .jsp gets the modified version of object from includedFileName2.jsp? -->
<jsp:include page="/includes/includedFileName3.jsp">
<jsp:param name="serializedObject" value="<%= serializedObject %>" />
</jsp:include>
includedFileName1.jsp
//Gson object used to convert serialized strings to java objects
Gson gson = new Gson();
ObjectType object = null;
if (null != request.getParameter("serializedObject")) {
object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
}
if (x = y) {object = somethingNew1;}
//is there a way to pass object back to the main.jsp?
includedFileName2.jsp
//Gson object used to convert serialized strings to java objects
Gson gson = new Gson();
ObjectType object = null;
if (null != request.getParameter("serializedObject")) {
object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
}
if (x = y) {object = somethingNew2;}
//is there a way to pass object back to the main.jsp?
includedFileName3.jsp
//Gson object used to convert serialized strings to java objects
Gson gson = new Gson();
ObjectType object = null;
if (null != request.getParameter("serializedObject")) {
object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
}
if (x = y) {object = somethingNew3;}
//is there a way to pass object back to the main.jsp?
オブジェクトは変更される場合とされない場合がありますが、3 つのすべてのインクルードからアクセスでき、オブジェクトの最新の変更にアクセスできる必要があります。
お時間をいただきありがとうございます。