【发布时间】:2013-11-22 09:44:56
【问题描述】:
我正在尝试在Select 标签中使用foreach 循环。
<html:select property="year" >
<s:iterator var="i" begin="${1}" end="${monthlyChargeForm.currentYear - 2000}" >
<s:set var="counter" value="${monthlyChargeForm.currentYear}"/>
<html:option value="${counter}">
<c:out value="${counter}"/>
</html:option>
<s:set var="counter" value="${counter-1}"/>
</s:iterator>
</html:select>
我试图在下拉列表中列出从当前年份到 YEAR : 2000 的所有年份。 但我的下拉菜单是空的。
动作类代码:我用过
// monthlyChargeForm.setCurrentYear(now.get(Calendar.YEAR) );
获取当前年份。
public class MonthlyChargeAction extends Action {
private ActionMessages messages;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
ServletContext context = getServlet().getServletContext();
BACUtils bacUtils = new BACUtils();
String sessionStatus = HtmlBean.isSessionOut(request.getSession(false), context);
if(!Constants.SUCCESS_STATUS.equals(sessionStatus)) {
return mapping.findForward("sessionOut");
}
String accesssStatus = HtmlBean.isSessionValid(request.getSession(false), context,
Properties.ACCESS_PROFILE[8][0]);
if(!Constants.SUCCESS_STATUS.equals(accesssStatus)) {
return mapping.findForward("sessionOut");
}
MonthlyChargeForm monthlyChargeForm = (MonthlyChargeForm)form;
Reports reports = new Reports();
String sUser =(String) request.getSession().getAttribute("USERID");
String returnVal = "";
int i = 0;
try {
monthlyChargeForm.setFromDate(bacUtils.getDate());
monthlyChargeForm.setToDate(bacUtils.getDate());
Calendar now = Calendar.getInstance();
String fromDate = monthlyChargeForm.getFromDate();
String toDate = monthlyChargeForm.getToDate();
String curentDate = bacUtils.getDate();
monthlyChargeForm.setCurrentYear(now.get(Calendar.YEAR) );
System.out.println("Current Year :::::::::" +
monthlyChargeForm.getCurrentYear());
AuditTrial.insertLog(5,sUser,null,"General Reports Module Loaded
Successfully",(String)
request.getSession().getAttribute("OPER_TYPE"),"S",request.getRemoteAddr(),context);
if(monthlyChargeForm.getPageIndex() == null ||
monthlyChargeForm.getPageIndex().trim().length() == 0)
monthlyChargeForm.setPageIndex(Integer.toString(BACUtils.getIntVal(
monthlyChargeForm.getPageIndex())));
if(monthlyChargeForm.getMonth()!=null &&
monthlyChargeForm.getYear()!=null )
{
monthlyChargeForm.setMonthlyChargeReport(
reports.getMonthlyChargeData(monthlyChargeForm, 10, context));
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Constants.SUCCESS_MAPPING);
return mapping.findForward(Constants.SUCCESS_MAPPING);
}
【问题讨论】:
-
请分享您的 Action 类代码...
-
您使用的是哪个版本的 Struts? Struts2 没有
html命名空间,Struts1 没有s命名空间。 -
使用了动作类代码。
-
动作是否有表单bean?
-
@user2761566 看起来您正在随机混合来自 S1 和 S2 的标签库。因为您使用的是 Struts 1,所以只使用 Struts 1 标签。
标签: java jsp struts jstl struts-1