package it.com.action; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import it.com.bean.Knowledge; import it.com.bean.Questions; import it.com.bean.Subject; import it.com.bean.Users; import it.com.service.TeacherService; import it.com.service.UsersService; import it.com.service.impl.ImpTeacherService; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sf.json.JSONArray; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class UsersAction { @Resource UsersService us; public UsersService getUs() { return us; } public void setUs(UsersService us) { this.us = us; } @Resource TeacherService ts; public TeacherService getTs() { return ts; } public void setTs(TeacherService ts) { this.ts = ts; } @RequestMapping("index.action") //跳转到学生、教师登陆页面 public ModelAndView index(){ return new ModelAndView("stu/login.jsp"); } @RequestMapping("welcome.action") //跳转到管理员欢迎页面 public ModelAndView welcome(){ return new ModelAndView("admin/welcome.jsp"); } @RequestMapping("forgetpwd.action") //跳转到管理员欢迎页面 public ModelAndView forgetpwd(HttpSession session){ int m=0; List<Users> list=us.findAdmin(); System.out.println(list); session.setAttribute("usernameA", list); session.setAttribute("m", m); return new ModelAndView ("admin/forgetpwd.jsp"); } @RequestMapping("tecwelcome.action") //跳转到教师欢迎页面 public ModelAndView tecwelcome(){ return new ModelAndView("teacher/welcome.jsp"); } @RequestMapping("nav.action") //跳转到管理员nav页面 public ModelAndView nav(){ return new ModelAndView("admin/nav.jsp"); } @RequestMapping("tecnav.action") //跳转到教师nav页面 public ModelAndView tecnav(){ return new ModelAndView("teacher/nav.jsp"); } @RequestMapping("table.action") //跳转到管理员table页面 public ModelAndView table(){ return new ModelAndView("admin/table.jsp"); } @RequestMapping("form.action") //跳转到管理员form页面 public ModelAndView form(){ return new ModelAndView("admin/form.jsp"); } @RequestMapping("tecform.action") //跳转到教师form页面 public ModelAndView tecform(){ return new ModelAndView("teacher/form.jsp"); } @RequestMapping("logintest.action") //管理员登陆验证 public ModelAndView logintest(HttpServletRequest request,HttpSession session){ String uri=""; String username=request.getParameter("username"); String userpwd=request.getParameter("userpwd"); String usertype=request.getParameter("usertype"); if(usertype.equals("administrator")){ int n=us.login(username, userpwd,0); if(n==1){ uri="admin/success.jsp"; }else{ uri="admin/login.jsp"; session.setAttribute("n", n); } Map map=new HashMap(); map.put("username", username); map.put("userpwd",userpwd); session.setAttribute("user", map); }else{ uri="admin/login.jsp"; } return new ModelAndView(uri); } //教师、学生登陆验证 @RequestMapping(value="login.action") public ModelAndView login(String username,String userpwd, int numyzm,HttpServletRequest res,HttpSession session){ String uri=""; String usertype=res.getParameter("usertype"); System.out.println("*--------"+usertype); System.out.println("*--------"+username); //System.out.println("---usertype---:"+usertype); if(usertype.equals("student")){ int nn=us.login(username, userpwd,2); //System.out.println("输出nn的值--------"+nn); int result=Integer.parseInt(session.getAttribute("result").toString()); //System.out.println(username+"===="+userpwd+"===="+numyzm); if(numyzm==result&&nn==1){ //System.out.println("我是学生--------"+nn); session.setAttribute("user", username); uri="stu/main.jsp"; }else{ uri="stu/login.jsp"; } }else if(usertype.equals("teacher")){ int nn=us.login(username, userpwd,1); //System.out.println("输出nn的值--------"+nn); int result=Integer.parseInt(session.getAttribute("result").toString()); //System.out.println(username+"===="+userpwd+"===="+numyzm); if(numyzm==result&&nn==1){ //System.out.println("我是老师--------"+nn); uri="tea.action"; }else{ uri="stu/login.jsp"; } }else{ uri="stu/login.jsp"; } return new ModelAndView(uri); } //通过页面获取的usertype查询学生或者教师的所有信息 @RequestMapping("selectUser.action") public ModelAndView selectUser(int usertype,HttpSession session){ List<Users> list=us.findUserByType(usertype); List <Subject>list1=ts.findSubject1(); int m1=list1.size(); session.setAttribute("m1", m1); session.setAttribute("listsub", list1); session.setAttribute("listusers", list); session.setAttribute("usertype", usertype); return new ModelAndView("admin/table.jsp");//跳转到查询的用户所有信息的界面 } //Users 操作 //插入学生或者教师的信息 @RequestMapping("insertUser.action") public ModelAndView insertUser(String username,String userpwd,int subjectid,int usertype,HttpSession session){ int n=us.insertUserByIdType(username, userpwd, subjectid, usertype); return new ModelAndView("admin/up.jsp");//跳转到插入后的用户界面 } //删除学生或者教师的信息 @RequestMapping("deleteUser.action") public ModelAndView deleteUser(int userid){ int n=us.deleUserById(userid); return new ModelAndView("admin/up.jsp");//更新用户信息后的界面 } //更新查询 @RequestMapping("UpdateSelectUsersById.action") public ModelAndView UpdateSelectUsersById(int userid,HttpSession session){ List<Users>list=us.UpdateSelectUsersById(userid); session.setAttribute("listuserbyid", list); return new ModelAndView("admin/update.jsp");//跳转到插入后的用户界面 } //更新 @RequestMapping("UpdateUserById.action") public ModelAndView UpdateUserById(String username,String userpwd,int subjectid,int usertype,int userid,HttpSession session){ int n=us.UpdateUserById(username, userpwd, subjectid, usertype, userid); session.setAttribute("usertype", usertype); return new ModelAndView("admin/up.jsp");//跳转到插入后的用户界面 } //课程操作 //查询所有课程 @RequestMapping("allsubject.action") public ModelAndView selectsubject(HttpSession session){ List <Subject> list=ts.findSubject1(); session.setAttribute("listless", list); return new ModelAndView("admin/less.jsp");//跳转到插入后的用户界面 } //插入 @RequestMapping("insertSub.action") public ModelAndView insertSub(String subjecttype){ int n=us.insSubjectById(subjecttype); return new ModelAndView("admin/su.jsp");//跳转到插入后的用户界面 } //删除 @RequestMapping("deleteSub.action") public ModelAndView deleteSub(HttpServletRequest request) throws UnsupportedEncodingException{ String subjecttype=new String(request.getParameter("subjecttype").getBytes("ISO-8859-1"),"utf-8"); int n=us.delSubjectById(subjecttype); return new ModelAndView("admin/su.jsp");//更新用户信息后的界面 } //更新查询 @RequestMapping("UpdateSelectSubById.action") public ModelAndView UpdateSelectSubById(int subjectid,HttpSession session){ List<Subject>list=us.upfindSubjectById(subjectid); session.setAttribute("listsu", list); return new ModelAndView("admin/updatesub.jsp");//跳转到插入后的用户界面 } //更新 @RequestMapping("UpdateSubById.action") public ModelAndView UpdateSubById(String subjecttype,int subjectid){ int n=us.upSubjectById(subjecttype,subjectid); return new ModelAndView("admin/su.jsp");//跳转到插入后的用户界面 } //管理员找回密码 @RequestMapping("sendtel.action") public void sendtel(HttpServletRequest request,HttpServletResponse response) throws IOException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); String telphone=request.getParameter("telphone"); Random rd=new Random(); int yzm=rd.nextInt(999)*999; System.out.println("yzm=--=="+yzm); final String username="shanxihuaxin"; //短信平台用户名 final String userpwd="hxzy2008"; //短信平台密码 final String content="管理员您好,您本次操作的验证码为"+yzm+",请尽快填写,谢谢"; //短信内容 final String url="http://service.winic.org:8009/sys_port/gateway/index.asp"; //接口 final String param="id="+username+"&pwd="+userpwd+"&to="+telphone+"&content="+content+"&otime="; String sr=us.fogetPost(url, param); System.out.println(sr); JSONArray json=JSONArray.fromObject(yzm); out.print(json); } //管理员验证码验证 @RequestMapping("telYz.action") public ModelAndView telYz(HttpServletRequest request,HttpServletResponse response){ return new ModelAndView("admin/updatepwd.jsp"); } //Excel批量导入用户 @RequestMapping("excel_insertUser.action") public ModelAndView ExcelInsertUser(HttpServletRequest request,HttpServletResponse response,HttpSession session) throws IOException{ /*String uri=request.getParameter("userUploadFile"); System.out.println("uri===="+uri);*/ int usertype=Integer.parseInt(request.getParameter("usertype")); InputStream is=new FileInputStream("c:\\Users.xls"); POIFSFileSystem fs=new POIFSFileSystem(is); HSSFWorkbook wb=new HSSFWorkbook(fs); HSSFSheet hssfSheet=wb.getSheetAt(0); //获取第一个Sheet页 //遍历行Row Map map=new HashMap(); for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){ //得到每个具体的行 HSSFRow hssfRow=hssfSheet.getRow(rowNum); if(hssfRow==null){ continue; } //System.out.print("hssfRow=行=== "+hssfRow); //遍历列 for(int cellNum=0;cellNum<=hssfRow.getLastCellNum();cellNum++){ HSSFCell hssfCell=hssfRow.getCell(cellNum); if(hssfCell==null){ continue; } if(cellNum==0) { map.put("username", hssfCell); }else if(cellNum==1){ map.put("userpwd", hssfCell); }else if(cellNum==2){ //System.out.println("hssfCell......"+hssfCell); //hssfCell.equals("Java") map.put("subjecttype", hssfCell); //System.out.println("map======"+map); String username=map.get("username").toString(); String userpwd=map.get("userpwd").toString(); //System.out.println("un=="+username+"........."+"up=="+userpwd); int subjectid=us.FindIdBysubType(map.get("subjecttype").toString()); //System.out.println("subjectid==="+subjectid); //System.out.println("------------------------"+username+" "+userpwd+" "+subjectid+" "+usertype); us.insertUserByIdType(username, userpwd, subjectid, usertype); } //System.out.print("hssfCell=列= "+hssfCell); } System.out.println(); } return new ModelAndView("admin/up.jsp"); } }

初嘤嘤嘤未来 LV7
2024年12月18日
ma406805131 LV19
2024年12月9日
2206371875 LV7
2024年3月14日
hongdongdong LV14
2023年12月3日
lbsers LV5
2023年5月6日
15152729192 LV3
2023年2月20日
唐唐丶 LV34
2023年2月19日
赵宇豪 LV1
2022年12月8日
1532593037 LV8
2022年11月30日
云翳tel青 LV11
2022年11月19日