在我的带有多个 div 标签的 JSP 页面上,我想让其中的一个特定的 div 不可刷新,以便它在 jsp 向 servlet 提交表单时保留其值。
一旦提交表单以上传文件,我就会丢失 div 数据。
如何在不使用 ajax 的情况下做到这一点?
我搜索了很多但只能找到使 div 可刷新的方法。
在我下面的 JSP 页面代码中,表单 myform 被提交到 upload.java 并被重定向回这个 jsp 页面。现在,我不想丢失 box div 的内容。
我的 JSP 页面
<div id="box">${f1stat}<br>${f2stat}<br>${f3stat}</div>
<div style="position: absolute; right: -5%; top: 2%;">
<form method="post" name="myform" action="upload" enctype="multipart/form-data">
Left File : <input type="file" name="dataFile1" id="fileChooser1" />
Right File : <input type="file" name="dataFile2" id="fileChooser2" />
Config File :<input type="file" name="dataFile3" id="fileChooser3" />
Geco File : <input type="file" name="dataFile4" id="fileChooser4" />
<input type="hidden" id="myField" value="" />
<button type="button" id="execute" onclick="ValidateFile()">Click to Upload files</button>
<button type= "button" id="execute" onclick="saveTextAsFile()">Click to execute</button>
</form>
</div>
框 div 在执行过程中由类似的命令填充
var err1 = document.getElementById("box");
err1.innerHTML = err1.innerHTML + "<br>" + "<span class='red'>Configuration file and Geco script should not be the same as left or right files. Please check your uploads</span>";
我像控制台显示一样使用 box div
Servlet 重定向方式
RequestDispatcher rd = request.getRequestDispatcher("geco.jsp");
rd.forward(request, response);
最佳答案
我想到的是在第一次加载时将数据保存到 session 范围的变量中,然后在设置它之前检查该变量在后续加载时是否有值。这样您的值(value)将得以保留:
<c:if test="${empty test}">
<c:set var="test" value="${objectWithData}" scope="session" />
</c:if>
然后使用保存在 var
中的对象的属性在您的 div 中显示信息。
关于javascript - 在 jsp 中使 div 不可刷新(不使用 AJAX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22377985/