0

ちょっとした裏話:

非常に大きくなったファイルで作業しているため、最終的に次のエラーが発生します。

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 つのすべてのインクルードからアクセスでき、オブジェクトの最新の変更にアクセスできる必要があります。

お時間をいただきありがとうございます。

4

1 に答える 1

0

ありがとう@home、@アシュリー...

これを実装する方法を再考し、request.setAttribute() と request.getAttribute() を使用して問題を解決しました。

<% 
    //set new parameters to be passed through to the jsp:include
    request.setAttribute("objectName", objectInstance);
%>
    <jsp:include page="/includes/requisitionClinicalConditionContent.jsp"/>
<%
    //get parameters passed from the jsp:include
    objectInstance = (object) request.getAttribute("objectName");
%> 

request.setAttribute() を使用してオブジェクトを通過し、それを jsp:include で受け取ります。jsp:include 内で変更された場合 (ほとんどの場合はそうではありませんが、値を変更する可能性のあるケースが 1 つまたは 2 つあります)、request.setAttribute(0 および私の親jspページでそれを受け取ります。

助けてくれてありがとう、すぐに返信できなくてごめんなさい。

于 2011-11-16T18:51:58.570 に答える