在我的带有多个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>
在执行期间,通过
等命令填充box divvar 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>";
我正在使用框div作为控制台显示
通过
重定向ServletRequestDispatcher rd = request.getRequestDispatcher("geco.jsp");
rd.forward(request, response);
答案 0 :(得分:0)
我们想到的是将第一次加载时的数据保存到会话范围变量中,然后在设置之前检查该变量是否在后续加载中具有值。这样你的价值就会保留下来:
<c:if test="${empty test}">
<c:set var="test" value="${objectWithData}" scope="session" />
</c:if>
然后使用var
中保存的对象的属性在div中显示信息。