一个小故事:
我正在处理一个非常大的文件,最终导致以下错误:
The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit.
为了解决这个问题,我一直在利用jsp:include
标签“模块化”文件。jsp:param
通过序列化对象并使用标记然后在 jsp:include 文件中反序列化,我已成功地将对象从主文件传递到包含文件。然而,就好像这些对象在主文件和多个包含文件中被使用、修改、重用和重新修改。我想知道是否有办法在渲染包含的文件后将对象传回主文件,或者是否有办法通过引用访问这些对象,以便可以在一个包含的文件和正确的实例中修改它们修改后的对象可以重用它下面的其他包含文件吗?
到目前为止,我已经考虑过pagecontext.setAttribute()
(这似乎不是 ref 并且似乎不允许我在修改到主文件后将值传回)和jsp:param
(与 几乎相同pagecontext.setAttribute()
)。
这是我到目前为止所拥有的:
下面的代码示例:(我希望这不会让任何人感到困惑。我不是在寻找语法更正,我只是在寻找一种允许通过引用访问相同对象的解决方案(例如全局变量以及include 标签)或者让我将对象传递回 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>
包含文件名1.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?
包含文件名2.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?
包含文件名3.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?
该对象可能会或可能不会被修改,但必须可以从所有三个包含中访问,并且对象的最新更改必须是可访问的。
感谢您的时间。