查找并上载学员
查找并下载学员
----------------------------------------------- jsp <script language="javascript" type="text/javascript"> function checkload(){ if(<%=request.getParameter("isSuccess")%>){ var temp = document.getElementById('form'); temp.action="http://localhost:8080/7e/data/download.doc"; temp.submit(); temp.action="/7e/jsp/admincp/student/downloadstudents.jsp"; } } </script> </head> <body onload="checkload();"> <form action="s/downloadStudents.action" method="post" id="form"> <div class="block style4"> <table cellspacing="3" cellpadding="3"> <tbody> <tr> <td colspan="4">请选择要下载的学员条件,都不填表示全部下载</td> </tr> <tr> <th>学员账号</th> <td><input type="text" value="" name="username"></td> <th>学员类型</th> <td><select name="utype"> <option value="">不限</option> <option value="0">临时学员</option> <option value="1">收费学员</option> <option value="2">补课学员</option> <option value="3">收费&补课学员</option> </select></td> </tr> <tr> <th>注册时间</th> <td colspan="3"> <s:textfield name="regdate" value="0"></s:textfield></td> <!-- <td colspan="3"><input type="text" onclick="showcalendar(event,this);" size="10" value="" name="dateline1"> ~ <input type="text" onclick="showcalendar(event,this);" size="10" value="" name="dateline2"> (YYYY-MM-DD)</td> --> </tr> <tr> <td colspan="4"> <input type="submit" class="submit" value="下载" name="searchsubmit"></td> </tr> </tbody> </table> </div> </form> ----------------------------------------------- struts <action name="downloadStudents" class="studentAction" method="downloadStudents" > <result >/jsp/admincp/student/downloadstudents.jsp?isSuccess=true</result> <param name="isSuccess">true</param> <result name="input">/index.jsp</result> </action> -----------------------------------------------action @Getter @Setter private int regdate; public String downloadStudents() { int position = 0; HttpServletRequest req = ServletActionContext.getRequest(); String path = req.getSession().getServletContext() .getRealPath(req.getRequestURI()); position = path.indexOf("7e-NewPlatform"); String filename = "download"; path = path.substring(0, position + 14); File file = new File(path + File.separator + filename + ".doc"); FileOutputStream fos = null; List<HomeMember> list = stdCourseService.findUserByProperty(username, path, regdate, position); try { // 编号 学员账号 密码 电子信箱 fos = new FileOutputStream(file); fos.write(("编号\t\t\t").getBytes()); fos.write("学员账号\t\t\t".getBytes()); fos.write("密码\t\t\t\r\n".getBytes()); fos.write("电子信箱\t\t\t\r\n".getBytes()); int i = 0; System.out.println(list.size() + "size"); for (HomeMember student : list) { System.out.println(i + "i"); fos.write((new Integer(++i) + "\t\t\t").getBytes()); System.out.println(student.getUid()); fos.write((student.getUsername() + "\t\t\t").getBytes()); fos.write((student.getPassword() + "\t\t\t\r\n").getBytes()); fos.write((student.getEmail() + "\t\t\t\r\n").getBytes()); } } catch (IOException e) { e.printStackTrace(); return INPUT; } try { fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); return INPUT; } return SUCCESS; } -----------------------------------------------service /** * 根据学员账号 学员类型 ( 临时学员 收费学员 补课学员 收费&补课学员) 还有 注册时间 * 学员ID 学员账号 真实姓名 学员类型 注册时间 ~ (YYYY-MM-DD) * @param name * @return */ public List<HomeMember> findUserByProperty(String name,String realname,int regdate ,int utype){ return stdCourseDao.findUserByProperty(name, realname, regdate, utype); } -----------------------------------------------dao /** * 根据学员账号 学员类型 ( 临时学员 收费学员 补课学员 收费&补课学员) 还有 注册时间 * 学员ID 学员账号 真实姓名 学员类型 注册时间 ~ (YYYY-MM-DD) * @param name * @return */ public List<HomeMember> findUserByProperty(String name,String realname,int regdate ,int utype) { String sql = "SELECT * FROM uchome_member WHERE regdate like '"+regdate+"%' and realname like '"+realname+"%' and utype like '"+utype+"%' and username like '"+name+"%'"; BeanPropertyRowMapper<HomeMember> argTypes = new BeanPropertyRowMapper<HomeMember>(HomeMember.class); List<HomeMember> list = getJdbcTemplate().query(sql, argTypes); return list; }SELECT * FROM uchome_member WHERE regdate like '%' and utype like '%' and username like 'ba%'; SELECT * FROM uchome_member WHERE regdate like '%' and utype like '%' and username like 'ba%'; SELECT * FROM uchome_member WHERE regdate like '0%' and realname like '%' and utype like '0%' and username like '%' SELECT * FROM uchome_member WHERE real like '%'