我需要有条件地将我的jsp页面设置为刷新并认为我在Refresh JSP Page找到了答案。我尝试在我的操作页面上使用response.setIntHeader("Refresh",10);
,但它无效,因此我尝试直接在我的Jsp
页面上使用它,如下所示,但仍然无法正常工作。这是一个Struts1
项目。
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested"%>
<html:form action="/permit/permittedFeatureList" >
<html:xhtml/>
<-- lots of code goes here -->
<% response.setIntHeader("Refresh",10); %>
</html:form>
当我用response.setIntHeader("Refresh",10);
替换<META HTTP-EQUIV="Refresh" CONTENT="10">
时,页面会刷新。我更喜欢在操作页面上使用Java代码,是否有人知道它为什么不起作用?谢谢!
修改
rupinderjeet47
让我展示我的所有代码,所以在这里。
<%@ page import="gov.mo.dnr.cwis.controller.system.permits.permittedFeature.PermittedFeatureListAction" %>
<%@ page import="java.util.Map" %>
<%@ page import="gov.mo.dnr.cwis.vo.ref.permit.PermitTypeInfo" %>
<%@ page import="gov.mo.dnr.utilities.CodeTableConstants.PermitType" %>
<%@ page import="gov.mo.dnr.utilities.CodeTableConstants.PermitStatus" %>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/DNRTags" prefix="DNRTags"%>
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested"%>
<%@page import="gov.mo.dnr.utilities.CodeTableConstants.PermitType"%><script language="Javascript" type="text/javascript">
function loadMgpPf()
{
document.permittedFeatureListForm.uglyJavaScriptHack.value="true";
document.permittedFeatureListForm.submit();
}
</script>
<DNRTags:checkLogon />
<html:form action="/permit/permittedFeatureList" >
<html:xhtml/>
<%
Object permitInstanceIdpf = request.getParameter("permitInstanceId");
if (permitInstanceIdpf == null) {
permitInstanceIdpf = request.getAttribute("permitInstanceId");
} if (permitInstanceIdpf == null) {
Map navMap = (Map) request.getSession().getAttribute("permitNavMap");
permitInstanceIdpf = Integer.parseInt(navMap.get("permitInstanceId").toString());
}
boolean permitStatus = false;
request.setAttribute("pfHeader",PermittedFeatureListAction.getPermittedFeatureHeader(permitInstanceIdpf));
java.util.Map<String,String> pstatus = (java.util.Map<String,String>)request.getAttribute("pfHeader");
if ( pstatus.get("permitStatus").equals(PermitStatus.DRAFT.status()))
{permitStatus = true;}
boolean gpcfFlag = false;
PermitTypeInfo ptInfo = (PermitTypeInfo)(session.getAttribute("permitTypeInfo"));
PermitType pt = PermitType.getPermitTypeById(ptInfo.getPermitTypeId());
if (pt== PermitType.GPCF || pt== PermitType.GPCF_CONST){
gpcfFlag= true;
}
%>
<h2>
<%if(gpcfFlag == true){ %>
GPCF
<% }%>
Permitted Features List
</h2>
<h3 align="center">
<bean:write scope="request" name="pfHeader" property="permitStatus" />
<logic:equal scope="request" name="pfHeader" property="permitStatus" value="Draft" >
- <bean:write scope="request" name="pfHeader" property="permitAction" />
</logic:equal>
<br />
Permit ID: <bean:write scope="request" name="pfHeader" property="permitNo" /><br />
</h3>
<%@ include file="/WEB-INF/pages/system/permits/facility/underEnforcement.jspf"%>
<%@ include file="/WEB-INF/pages/system/permits/messages.jspf" %>
<div id="permitReadOnly">
<table width="100%">
<tr valign="top">
<td width="25%">
<fieldset>
Facility ID: <bean:write scope="request" name="pfHeader" property="facilityId" /><br />
Facility: <bean:write scope="request" name="pfHeader" property="facilityName" /><br />
Owner Name: <bean:write scope="request" name="pfHeader" property="facilityOwner" /><br />
County: <bean:write scope="request" name="pfHeader" property="countyName" /><br />
Region: <bean:write scope="request" name="pfHeader" property="region" /><br />
</fieldset>
</td>
<td width="25%">
<fieldset>
Permit Type: <bean:write scope="request" name="pfHeader" property="permitType" /><br />
Non-NPDES Type: <bean:write scope="request" name="pfHeader" property="subType" /><br />
Construction Type: <bean:write scope="request" name="pfHeader" property="conType" /><br />
Initial Date: <bean:write scope="request" name="pfHeader" property="initialDate" /><br />
</fieldset>
</td>
<td width="25%">
<fieldset>
Issue Date: <bean:write scope="request" name="pfHeader" property="issueDate" /><br />
Effective Date: <bean:write scope="request" name="pfHeader" property="effDate" /><br />
Expiration Date: <bean:write scope="request" name="pfHeader" property="expDate" /><br />
Termination Date: <bean:write scope="request" name="pfHeader" property="termDate" /><br />
</fieldset>
</td>
<td width="25%">
<fieldset>
<%if(gpcfFlag == true){ %>
GPCF Version Number: <bean:write scope="request" name="pfHeader" property="gpcfVersion" /><br />
MGP Version Number: <bean:write scope="request" name="pfHeader" property="mgpVersion" /><br />
MGP Permit Name: <bean:write scope="request" name="pfHeader" property="mgpName" /><br />
<%} %>
</fieldset>
</td>
</tr>
</table>
</div>
<%-- Add gpcf permitted feature --%>
<DNRTags:AccessRoles roleList="System Administrator, Permit 1, Permit 2, Permit 3">
<%if(gpcfFlag == true){ %>
<div align="right">
<table width="100%" cellspacing="0" class="dataEntryBorder">
<tr>
<td colspan="7" class="rowsecthead">GPCF Permitted Feature</td>
</tr>
<tr>
<td width="97" align="right"> </td>
<td width="152" align="right"><span class="required">*</span><label for="permittedFeatureNo">No:</label></td>
<td width="229" align="left">
<html:text property="permittedFeatureNo" styleId="permittedFeatureNo" size="3" maxlength="3" />
</td>
<td width="26" class="columnseperator"></td>
<td align="right"><span class="required">*</span><label for="activeDate">Active Date or Date Limit Sets Can Be Added:</label></td>
<td colspan="2" align="left" width="229">
<html:text property="activeDate" styleId="activeDate" size="10" maxlength="10" onblur="checkdate(activeDate);"/>
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="right">
<label for="mgpPermittedFeatureId">
<span class="required">*</span>MGP Permitted Features
</label>
</td>
<td align="left">
<% request.setAttribute("mgpPfCodes",PermittedFeatureListAction.getMgpPfCodes(permitInstanceIdpf)); %>
<span class="borderbottom">
<html:hidden property="uglyJavaScriptHack" />
<html:select property="mgpPermittedFeatureId" styleId="mgpPermittedFeatureId" onchange=" loadMgpPf(); ">
<html:option value=""></html:option>
<html:options collection="mgpPfCodes" property="value" labelProperty="label" />
</html:select>
</span>
</td>
<td class="columnseperator"></td>
<td align="right">Type Description:<br /></td>
<td colspan="2" align="left">
<bean:write name="permittedFeatureListForm" property="typeDescription" />
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="right"> </td>
<td> </td>
<td class="columnseperator"></td>
<td align="right">Waste Type:</td>
<td colspan="2" align="left">
<bean:write name="permittedFeatureListForm" property="wasteType" />
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="right" valign="top"><label for="comments">Comments: </label></td>
<td align="left"><html:textarea property="comments" styleId="comments" cols="30" rows="3" /></td>
<td class="columnseperator"></td>
<td align="right" valign="top">Comments:</td>
<td colspan="2" valign="top" align="left">
<bean:write name="permittedFeatureListForm" property="mgpPfComments" />
</td>
</tr>
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Terminated" >
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Retired" >
<tr>
<td colspan="7" align="center">
<html:submit property="action" styleClass="button" value="Add" alt="Add"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
<html:submit property="action" styleClass="button" value="Clear" alt="Clear"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
</td>
</tr>
</logic:notEqual>
</logic:notEqual>
</table>
</div>
<%} %>
</DNRTags:AccessRoles>
<div align="right">
<logic:notPresent scope="request" name="dnr.mo.gov.permits.permittedFeatureList">
<%
try {
PermittedFeatureListAction.reload(request);
} catch (Exception e) {
}
%>
</logic:notPresent>
<logic:present scope="request" name="dnr.mo.gov.permits.permittedFeatureList">
<%if(gpcfFlag == false){ %>
<table width="100%" class="searchresults bordersingle" >
<caption>Click on a Permitted Feature ID link below to view, edit, or delete the Permitted Feature.</caption>
<thead>
<tr>
<th width="10%"><center>No.</center></th>
<th width="15%" align="center">Primary Indicator</th>
<th width="17%" align="center">Type</th>
<th width="10%" align="center">Active</th>
<th width="10%" align="center">Complete</th>
<th width="18%" align="center">Mapped</th>
<th width="20%" align="center">Trace Status</th>
</tr>
</thead>
<tbody>
<% int count = 0; %>
<logic:iterate id="row" scope="request" name="dnr.mo.gov.permits.permittedFeatureList" property="permittedFeatureList" >
<% if( count % 2 == 0 ) { %>
<tr class="rowaltcolor">
<% } else { %>
<tr bgcolor="white">
<% } %>
<td align="center">
<html:link action="/permit/permittedFeatureBasic" paramId="permittedFeatureId"
paramName="row" paramProperty="permittedFeatureId">
<bean:write name="row" property="permittedFeatureNum" />
</html:link>
</td>
<td align="center">
<label for="Permitted Feature ${row.selectedPrimaryId}" class="hidden">Primary Indicator</label>
<html:radio idName="row" value="permittedFeatureId" property="selectedPrimaryId" styleId="Permitted Feature ${row.selectedPrimaryId}"/>
</td>
<td align="left">
<bean:write name="row" property="permittedFeatureTypeDesc" />
</td>
<td align="center">
<bean:write name="row" property="isActive" />
</td>
<td align="center">
<bean:write name="row" property="isComplete" />
</td>
<td align="center">
<bean:write name="row" property="isMapped" />
</td>
<td align="center">
<bean:write name="row" property="permittedFeatureTraceStatus" />
</td>
</tr>
<% count++; %>
</logic:iterate>
</tbody>
</table>
<%} %>
<%if(gpcfFlag == true){ %>
<table width="100%" class="searchresults bordersingle" >
<caption>Click on a Permitted Feature ID link below to view, edit, or delete the Permitted Feature.</caption>
<thead>
<tr>
<th width="10%" align="center">GPCF PF No.</th>
<th width="15%" align="center">MGP PF No.</th>
<th width="17%" align="center">Primary Indicator</th>
<th width="15%" align="center">Type</th>
<th width="10%" align="center">Active</th>
<th width="10%" align="center">Complete</th>
<th width="17%" align="center">Mapped</th>
<th width="20%" align="center">Trace Status</th>
</tr>
</thead>
<tbody>
<% int gcount = 0; %>
<logic:iterate id="row" scope="request" name="dnr.mo.gov.permits.permittedFeatureList" property="permittedFeatureList" >
<% if( gcount % 2 == 0 ) { %>
<tr class="rowaltcolor">
<% } else { %>
<tr bgcolor="white">
<% } %>
<td align="center">
<html:link action="/permit/permittedFeatureBasic" paramId="permittedFeatureId"
paramName="row" paramProperty="permittedFeatureId">
<bean:write name="row" property="permittedFeatureNum" />
</html:link>
</td>
<td align="center">
<bean:write name="row" property="mgpPermittedFeatureNum" />
</td>
<td align="center">
<logic:equal name="row" property="isActive" value="Yes">
<label for="Permitted Feature ${row.selectedPrimaryId}" class="hidden">Primary Indicator</label>
<html:radio idName="row" value="permittedFeatureId" property="selectedPrimaryId" styleId="Permitted Feature ${row.selectedPrimaryId}"/>
</logic:equal>
<logic:notEqual name="row" property="isActive" value="Yes">
<label for="Permitted Feature ${row.selectedPrimaryId}" class="hidden">Primary Indicator</label>
<html:radio idName="row" value="permittedFeatureId" property="selectedPrimaryId" styleId="Permitted Feature ${row.selectedPrimaryId}" disabled="true" />
</logic:notEqual>
</td>
<td align="left">
<bean:write name="row" property="permittedFeatureTypeDesc" />
</td>
<td align="center">
<bean:write name="row" property="isActive" />
</td>
<td align="center">
<bean:write name="row" property="isComplete" />
</td>
<td align="center">
<bean:write name="row" property="isMapped" />
</td>
<td align="center">
<bean:write name="row" property="permittedFeatureTraceStatus" />
</td>
</tr>
<% gcount++; %>
</logic:iterate>
</tbody>
</table>
<%} %>
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Terminated" >
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Retired" >
<DNRTags:AccessRoles roleList="System Administrator, Permit 1, Permit 2">
<html:submit value="Save Changes" alt="Save Changes"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
</DNRTags:AccessRoles>
</logic:notEqual>
</logic:notEqual>
<logic:equal scope="request" name="pfHeader" property="permitStatus" value="Draft" >
<DNRTags:AccessRoles roleList="Permit 3">
<html:submit value="Save Changes" alt="Save Changes"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
</DNRTags:AccessRoles>
</logic:equal>
</logic:present>
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Terminated" >
<logic:notEqual scope="request" name="pfHeader" property="permitStatus" value="Retired" >
<DNRTags:AccessRoles roleList="System Administrator, Permit 1, Permit 2">
<%if(gpcfFlag == false){ %>
<logic:equal scope="request" name="pfHeader" property="isCafo" value="Y" >
<html:submit value="Add CAFO Permitted Feature" alt="Add CAFO Permitted Feature"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
</logic:equal>
<html:submit value="Add Permitted Feature" alt="Add Permitted Feature"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
<% }%>
</DNRTags:AccessRoles>
</logic:notEqual>
</logic:notEqual>
<logic:equal scope="request" name="pfHeader" property="permitStatus" value="Draft" >
<DNRTags:AccessRoles roleList="Permit 3">
<%if(gpcfFlag == false){ %>
<logic:equal scope="request" name="pfHeader" property="isCafo" value="Y" >
<html:submit value="Add CAFO Permitted Feature" alt="Add CAFO Permitted Feature"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
</logic:equal>
<html:submit value="Add Permitted Feature" alt="Add Permitted Feature"
property="action" styleClass="button"
onmouseover="this.className='button buttonhov'"
onmouseout="this.className='button'" />
<% }%>
</DNRTags:AccessRoles>
</logic:equal>
</div>
<logic:equal scope="request" name="dnr.mo.gov.permits.permittedFeatureList" property="refreshJspPage" value="true" >
<META HTTP-EQUIV="Refresh" CONTENT="30">
</logic:equal>
</html:form>
答案 0 :(得分:0)
response.setHeader("Refresh", "3");
response.setIntHeader("Refresh", 3);
两个都在工作。所以,问题出在您的代码很多块中。您是否在此行之前修改了response
?
替代方案:(不推荐)
您的JSP或HTML
<meta http-equiv="refresh" content="<%Variables.refreshTime%>">
创建一个包含公共静态变量的Variables类:
public class Variables{
public static String refreshTime = "60";
}
然后,您可以从代码中的任何位置更新它,例如
Variables.refreshTime = "120"; //effects after page reload, same as setIntHeader()