我需要将值从一个jsp传递到另一个jsp,然后在另一个jsp中处理这些值,然后jsp将包含在第一个jsp中。
我需要传递的jsp变量是从Comp_Mps_hs.jsp到Comp_Mps_hs_diff.jsp
<jsp:useBean id="ref" class="comp_Mps.Comp_Mps_hs"/>
<br>
<%
//Comaprision obj = new Comaprision();
String s_date= request.getParameter("startdate");
pageContext.setAttribute("s_date", s_date);
String e_date= request.getParameter("enddate");
pageContext.setAttribute("e_date", e_date);
ref.refarray_vac1(s_date,e_date);
ref.ClosestToMultiplesOfTen_User(s_date,e_date);
%>
<%
//Comaprision reference = new Comaprision();
String ref_name= request.getParameter("ref_logtime");
pageContext.setAttribute("ref_name", ref_name);
ref.FindClosestToMultiplesOfTen(ref_name);
ref.refernece(ref_name);
%>
<br><br><br>
<table width = "170%" border = "1" cellspacing="0" cellpadding="0">
<tr>
<th>Date_Time</th>
<th>beam_current</th>
<th>beam_energy</th>
<%
for(int i=51; i<99;i++){
%>
<th>p<%=i%>_readback</th>
<th>p<%=i%>_setvalue</th>
<th>p<%=i%>_vmeset</th>
<th>p<%=i%>_dacbyadc</th>
<%
}
%>
<!--
</tr>
<c:set var="count" value="0" scope="session" />
<c:forEach var="row" items="${ref.refarray_vac1(param.startdate,param.enddate)}">
<c:forEach var="r" items="${ref.refernece(param.ref_logtime)}" begin="${count}" end="${count}">
<tr bgcolor="darkgray ">
<td><c:out value="${r.logtime}"></c:out></td>
<td>
<c:out value="${r.beam_current}"></c:out> </td>
<td>
<c:out value="${(r.beam_energy)}"/>
</td>
<td>
<fmt:formatNumber value="${(r.p51_readback)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${(r.p51_readback)}"/>
</td>
<td>
<fmt:formatNumber value="${(r.p51_setvalue)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${(mm)}"/>
</td>
</tr>
<!-- For user_selection color name-- darkkhaki -->
<tr bgcolor="cornsilk">
<td><c:out value="${row.logtime}"></c:out></td>
<td>
<c:out value="${row.beam_current}"></c:out> </td>
<td>
<c:out value="${(row.beam_energy)}"/>
</td>
<td>
<fmt:formatNumber value="${(row.p51_readback)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${(row.p51_readback)}"/>
</td>
<td>
<fmt:formatNumber value="${(row.p51_setvalue)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${(mm)}"/>
</td>
</tr>
<tr>
<td>Deviation</td>
<jsp:include page="Mps_Hs_diff.jsp"></jsp:include>**Here I need to include another jsp as the cod ewas becoming large**
<c:set var="count" value="${count + 1}" scope="session" />
</c:forEach>
</c:forEach>
</table>
</body>
我需要在此页面中声明的r和row值的另一个页面是
<body>
<jsp:useBean id="ref" class="comp_Mps.Comp_Mps_hs"/>
<br>
<%
//Comaprision obj = new Comaprision();
String s_date= request.getParameter("startdate");
pageContext.setAttribute("s_date", s_date);
String e_date= request.getParameter("enddate");
pageContext.setAttribute("e_date", e_date);
ref.refarray_vac1(s_date,e_date);
ref.ClosestToMultiplesOfTen_User(s_date,e_date);
%>
<%
//Comaprision reference = new Comaprision();
String ref_name= request.getParameter("ref_logtime");
pageContext.setAttribute("ref_name", ref_name);
ref.FindClosestToMultiplesOfTen(ref_name);
ref.refernece(ref_name);
%>
<br><br><br>
<table width = "170%" border = "1" cellspacing="0" cellpadding="0">
<c:set var="row" value="${ref.refarray_vac1(param.startdate,param.enddate)}"></c:set>
<c:set var="r" value="${ref.refernece(param.ref_logtime)}"></c:set>
<tr>
<td scope="row" style="${r.beam_current-row.beam_current eq 0 ? 'background-color: lime':'background-color: pink'}">
<fmt:formatNumber value="${(r.beam_current-row.beam_current)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${mm}" ></c:out></td>
<td scope="row" style="${r.beam_energy-row.beam_energy eq 0 ? 'background-color: lime':'background-color: pink'}">
<fmt:formatNumber value="${(r.beam_energy-row.beam_energy)}" maxFractionDigits="2" minIntegerDigits="2" var="mm"></fmt:formatNumber>
<c:out value="${mm}" ></c:out></td>
<td style="${r.p51_readback-row.p51_readback eq 0 ? 'background-color: lime':'background-color: pink'}">
<fmt:formatNumber value="${((r.p51_readback-row.p51_readback))}" maxFractionDigits="2" minIntegerDigits="2" pattern="##.##" var="nn"></fmt:formatNumber>
<c:out value="${nn}"></c:out>
<fmt:formatNumber value="${(r.p51_readback-row.p51_readback)/r.p51_readback}" maxFractionDigits="2" minIntegerDigits="2" type="percent" var="mm"></fmt:formatNumber>
<c:out value="(${mm})" ></c:out></td>
但是第一页从未被用户调用,另一个页面被调用,其按钮单击第一个jsp被调用。因此,我所包含的页面中的值永远不会被处理,因为它永远不会被调用。
答案 0 :(得分:0)
一种选择是使用会话范围,以便在当前会话期间使您的变量在任何JSP或servlet中可用。
您可以将变量存储在会话范围中:
HttpSession session = request.getSession();
String variableToPass = "hello";
session.setAttribute("variableToPass", variableToPass);
而且,您可以像这样访问它们:
HttpSession session = request.getSession();
String variablePassed = session.getAttribute("variableToPass");
希望它有用。