jsp页面年份下拉框生成当前年的前n年和后n年

本文介绍如何利用Java中的Calendar类生成一个包含过去10年至未来10年的下拉菜单选项,实现用户选择特定年份的功能。代码示例展示了如何通过JSP页面设置默认选中项,以便用户在页面加载后看到之前的选择。

因为要用到Calendar方法,首先要导入Calendar类所在的包。

<%@ page import="java.util.Calendar"%>

  1. <select name='year'>
  2. <option></option>
  3. <% Calendar cal = Calendar.getInstance();
  4. int year = cal.get(Calendar.YEAR)-10;
  5. for(int i=1; i<=21; i++){
  6. String str = String.valueOf(year);
  7. if(str.equals(request.getParameter("year"))){
  8. %>
  9. <option selected="selected"><%=str%></option>
  10. <%} else{%>
  11. <option><%=str%></option>
  12. <%} year = year + 1;
  13. }%>
  14. </select>

当页面刷新后,使用if语句判断以前被选中的年份显示在页面

然后就可以在前端查看效果,并根据需要进行调整

转自https://blog.youkuaiyun.com/u012739535/article/details/24342695

public String execute() throws Exception { TSysDepartment depart = dao.findBySid(TSysDepartment.class, getCurrentUser().getFrybm()); /* * List<String> drug = * Arrays.asList("化学药品检验检测中心","藏药检验检测中心","中药检验检测中心","药品包装材料检验检测中心"); * List<String> hzdrug = Arrays.asList("化妆品检验检测中心"); List<String> ylqx = * Arrays.asList("医疗器械检验检测中心","药品包装材料检验检测中心"); List<String> all = * Arrays.asList("业务保障部","院部","药理与卫生学检验检测评价中心","质量技术部"); */ String drug="化学药品检验检测中心,藏药检验检测中心,中药检验检测中心,药品包装材料检验检测中心"; String hzdrug="化妆品检验检测中心"; String ylqx="医疗器械检验检测中心,药品包装材料检验检测中心"; String all="业务保障部,院部,药理与卫生学检验检测评价中心,质量技术部"; String viewModule = ""; String nn = ""; String ksmc=depart.getFdepmc(); if(all.contains(ksmc)) { nn="医疗器械"; viewModule+="医疗器械化妆品药品"; } if(ylqx.contains(ksmc)) { nn="医疗器械"; viewModule+="医疗器械"; } if(drug.contains(ksmc)) { nn = "药品"; viewModule+="药品"; } if(hzdrug.contains(ksmc)) { nn= "化妆品"; viewModule+="化妆品"; } if(Util.isEmpty(nn)) { nn="医疗器械"; } if(StringUtils.isEmpty(nodename)) { nodename = nn; } ActionContext.getContext().put("viewModule", viewModule); if(!Util.isEmpty(download)){ page.setPageSize(10000000); page.setPageNo(1); //dao.queryPage1(page, getNodename()); }else{ if(Util.isEmpty(isNotSetdefaultValue)) { page.getCondition().put("nf", Calendar.getInstance().get(Calendar.YEAR)+""); } dao.queryPage(page, getNodename(),null); } if (!Util.isEmpty(download)) { if("ypsc".equals(download)) { page.getCondition().put("lccb_jymdxl","省级药品抽检"); } if("scxm".equals(download)||"scjbxx".equals(download)) { page.getCondition().put("lccb_jymdxl","省级医疗器械抽检"); } dao.queryPagedc(page, getNodename()); list = page.getDataRows(); YlqxSubject newqx = new YlqxSubject() ; String[] gds; String[] jgs; String agent = getRequest().getHeader("User-Agent"); String filename = Util.getDownloadFileName(getNodename(), agent); getResponse().setContentType("application/vnd.ms-excel"); getResponse().setHeader("Content-disposition", "attachment;filename=" + filename + ".xls"); if(download.equals("xm")||download.equals("scxm")||download.equals("scjbxx")){ long l1 = System.currentTimeMillis(); if("药品".equals(nodename)) { List<Map<String,Object>> makeList = new ArrayList<Map<String,Object>>(); List<Map<String,Object>> dataResult = new ArrayList(list); List<String> uids = ListTools.extractValueByMapKey(dataResult, "lccb_jianpUID"); if(uids.isEmpty()) return "ypxm"; List<DrugSubject> subjects = (List<DrugSubject>) dao.findResultByListLimit("from DrugSubject where lcs_jianpUID in (:param) order by lcs_snum", uids,1000); List<TSysPerson> persons = dao.findAll(TSysPerson.class); for(Map basic:list){ String uid = (String) basic.get("lccb_jianpUID"); List<DrugSubject> subject=ListTools.match(subjects, "lcs_jianpUID", uid); if(subject.isEmpty()) makeList.add(basic); for (DrugSubject s : subject) { Map temp = new HashMap(basic); temp.put("lcs_snum", s.getLcs_snum()); temp.put("lcs_jydl", s.getLcs_jydl()); temp.put("lcs_jyxm", s.getLcs_jyxm()); temp.put("lcs_bzgd", s.getLcs_bzgd()); temp.put("lcs_jyjg", s.getLcs_jyjg()); temp.put("lcs_jyjl", s.getLcs_jyjl()); temp.put("lcs_jyry", s.getLcs_jyry()); temp.put("lcs_jyks",s.getLcs_jyks()); String lcs_sfzj = s.getLcs_sfzj(); List<TSysPerson> fuhrs = new ArrayList<TSysPerson>(); if("主检".equals(lcs_sfzj) && !Util.isEmpty(basic.get("lccb_zjfhrid"))) { fuhrs = ListTools.match(persons, "fsid", (String)basic.get("lccb_zjfhrid")); }else if("协1".equals(lcs_sfzj)&& !Util.isEmpty(basic.get("lccb_xj1fhrid"))) { fuhrs = ListTools.match(persons, "fsid", (String)basic.get("lccb_xj1fhrid")); }else if("协2".equals(lcs_sfzj)&& !Util.isEmpty(basic.get("lccb_xj2fhrid"))) { fuhrs = ListTools.match(persons, "fsid", (String)basic.get("lccb_xj2fhrid")); }else if("协3".equals(lcs_sfzj)&& !Util.isEmpty(basic.get("lccb_xj3fhrid"))) { fuhrs = ListTools.match(persons, "fsid", (String)basic.get("lccb_xj3fhrid")); } temp.put("lcs_fuhr", fuhrs.isEmpty()?"":fuhrs.get(0).getFrymc());//校对者 temp.put("lcs_pf", s.getLcs_pf());//工作量 makeList.add(temp); } } page.setDataRows(makeList); return "ypxm"; }else if("医疗器械".equals(nodename)) { for(Map basic:list){ String uid = (String) basic.get("lccb_jianpUID"); List<YlqxSubject> subject=dao.findByProperty(YlqxSubject.class, "lcs_jianpUID", uid,"lcs_snum"); basic.put("sujects", subject); String zzjl = (String) basic.get("lccb_zzjl"); String s=""; String jyjl=""; if(!Util.isEmpty(zzjl)) { for(YlqxSubject ss:subject) { jyjl=ss.getLcs_jyjl(); if(!Util.isEmpty(jyjl)&&jyjl.indexOf("不")!=-1) { if(!jyjl.equals("不适用")) { s=s+ss.getLcs_jyxm()+","; } } } } if(!Util.isEmpty(s)) { basic.put("bhgxm", s.substring(0,s.length()-1)); } } if("scxm".equals(download)) { return "scqxxm"; }else if("scjbxx".equals(download)){ return "scjbxx"; }else { return "qxxm"; } } return null; } List<Map<String,Object>> makeList = new ArrayList<Map<String,Object>>(); List<Map<String,Object>> dataResult = new ArrayList(list); for(Map basic:list){ String uid = (String) basic.get("lccb_jianpUID"); String zzjl = (String) basic.get("lccb_zzjl"); if("药品".equals(nodename)) { List<DrugSubject> subject=dao.findByProperty(DrugSubject.class, "lcs_jianpUID", uid,"lcs_snum"); if(!Util.isEmpty(zzjl)&&zzjl.indexOf("不")!= -1&&!zzjl.equals("不适用")) { String ss=""; for (DrugSubject s : subject) { if(s.getLcs_jyjl().indexOf("不")!= -1&&s.getLcs_jyjl()!="不适用") { if(!Util.isEmpty(s.getLcs_jyxm())) { ss+=s.getLcs_jyxm()+";"; }else { ss+=s.getLcs_jydl()+";"; } } } basic.put("jyxms", ss); ss=""; }else{ basic.put("jyxms","/"); } }else if("医疗器械".equals(nodename)) { List<YlqxSubject> subjects=dao.findByProperty(YlqxSubject.class, "lcs_jianpUID", uid,"lcs_snum"); if(!Util.isEmpty(zzjl)&&zzjl.indexOf("不")!= -1&&!zzjl.equals("不适用")) { String ss=""; for (YlqxSubject s : subjects) { if(s.getLcs_jyjl().indexOf("不")!= -1&&s.getLcs_jyjl()!="不适用") { if(!Util.isEmpty(s.getLcs_jyxm())) { ss+=s.getLcs_jyxm()+";"; }else { ss+=s.getLcs_jydl()+";"; } } } basic.put("jyxms", ss); ss=""; }else{ basic.put("jyxms","/"); } } } page.setDataRows(list); if("药品".equals(nodename) || "医疗器械".equals(nodename)) { this.ylqxCxtjcldc();//统计数据处理 } if("ypsc".equals(download)) { return "xls1"; }else { return "xls"; } }else if(!Util.isEmpty(downloadname)){ /*String agent = getRequest().getHeader("User-Agent"); String filename = Util.getDownloadFileName(getNodename(), agent); getResponse().setContentType("application/vnd.ms-excel"); getResponse().setHeader("Content-disposition", "attachment;filename=" + filename + ".xls");*/ ServletContext servletcontext=ServletActionContext.getRequest().getSession().getServletContext(); List<List<Map<String, Object>>> datas=new ArrayList(); page.setPageSize(999999); page.setSortColumn("lccb_chouyjpzbh"); dao.queryPage(page, getNodename(),ids); datas.add(page.getDataRows()); dao.queryPage1(page, getNodename(),ids); datas.add(page.getDataRows()); ExcelUtil.DynamicOperateExcelUtils(servletcontext.getRealPath("mould/国抽化妆品数据上传模板.xlsx"),new String[]{"化妆品样品信息","化妆品检验项目"}, datas); //return "xls1"; return null; } else { this.ylqxCxtjcl();//统计数据处理 List<TSysDepartment> jyks = dao.findByProperty(TSysDepartment.class, "fisjyjg", "是"); ActionContext.getContext().put("jyks", jyks); //获取检验目的大类,检验目的小类 Tools.cxtjJymddlAndXl(dao.findAll(TreeFields.class),nodename); return SUCCESS; } }
10-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值