您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Java兼職平臺系統(tǒng)如何實(shí)現(xiàn)”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
環(huán)境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
項(xiàng)目技術(shù):
HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等.
/** * @Author yy * @Description 登錄 * @Date 2022.2.17 */ public class LoginController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { JSONObject jsonObject = new JSONObject(); String username = req.getParameter("username"); String password = req.getParameter("password"); resp.setCharacterEncoding("UTF-8"); HttpSession session = req.getSession(); if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { jsonObject.put("code", 2000); jsonObject.put("flag", "fail"); jsonObject.put("user", null); jsonObject.put("msg", "usernameOrPasswordIsBank");//用戶名密碼不能為空 resp.getWriter().print(jsonObject); return; } password = MyMD5Util.encrypt(password); System.out.println(password); BusinessUserVO businessUserVO = new BusinessUserVO(); businessUserVO.setUsername(username); businessUserVO.setPassword(password); StudentUserVO studentUserVO = new StudentUserVO(); studentUserVO.setUsername(username); studentUserVO.setPassword(password); String flag1 = null; String flag2 = null; try { flag1 = BusinessUserDao.selectUsername(businessUserVO); if ("ok".equals(flag1)) {//企業(yè)用戶名存在 BusinessUserDTO businessUserDTO = BusinessUserDao.select(businessUserVO); if (businessUserDTO != null) { jsonObject.put("code", 2000); jsonObject.put("flag", "success");//登錄成功 jsonObject.put("user", businessUserDTO); jsonObject.put("msg", "login_success"); session.setAttribute("businessUser",businessUserDTO); resp.getWriter().print(jsonObject); return; } else { jsonObject.put("code", 2000); jsonObject.put("flag", "fail");//登錄失敗 jsonObject.put("user", null); jsonObject.put("msg", "passwordError");//密碼錯(cuò)誤 resp.getWriter().print(jsonObject); return; } } flag2 = StudentUserDao.selectUsername(studentUserVO); if ("ok".equals(flag2)) {//學(xué)生用戶名存在 StudentUser studentUser = StudentUserDao.select(studentUserVO); if (studentUser != null) { jsonObject.put("code", 2000); jsonObject.put("flag", "success");//登錄成功 jsonObject.put("user", studentUser); jsonObject.put("msg", "login_success"); session.setAttribute("studentUser",studentUser); resp.getWriter().print(jsonObject); return; } else { jsonObject.put("code", 2000); jsonObject.put("flag", "fail");//登錄失敗 jsonObject.put("user", null); jsonObject.put("msg", "passwordError");//密碼錯(cuò)誤 resp.getWriter().print(jsonObject); return; } } //用戶名不存在,前往注冊 jsonObject.put("code", 2000); jsonObject.put("flag", "fail");//登錄失敗 jsonObject.put("user", null); jsonObject.put("msg", "usernameIsNotExist");//密碼錯(cuò)誤 resp.getWriter().print(jsonObject); return; } catch (SQLException throwables) { throwables.printStackTrace(); } return; } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { doGet(req, resp); } }
public class AdminLoginController extends HttpServlet { @SneakyThrows @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String username = req.getParameter("username"); String password = req.getParameter("password"); password = MyMD5Util.encrypt(password); JSONObject jsonObject = new JSONObject(); HttpSession session = req.getSession(); Admin admin = new Admin(username, password); Admin adminFromDB = AdminDao.findByUsernamePassword(admin); if (adminFromDB!=null){ jsonObject.put("code",2000); jsonObject.put("msg","login_success"); jsonObject.put("admin",adminFromDB.getUsername()); jsonObject.put("flag","success"); resp.getWriter().print(jsonObject); session.setAttribute("admin",adminFromDB); return; }else { jsonObject.put("code",2000); jsonObject.put("msg","no admin"); jsonObject.put("admin",null); jsonObject.put("flag","fail"); resp.getWriter().print(jsonObject); return; } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doGet(req, resp); } }
public class SubmitResumeController extends HttpServlet { @SneakyThrows @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { JSONObject jsonObject = new JSONObject(); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); req.setCharacterEncoding("UTF-8"); upload.setHeaderEncoding("UTF-8"); List<FileItem> items = upload.parseRequest(req); StringBuffer sb = new StringBuffer(); String resumeFile = null; for (FileItem item : items) { String name = item.getFieldName(); InputStream inputStream = item.getInputStream(); if (!name.equals("resumeFile")){ String string = item.getString(); string = new String(string.getBytes("ISO8859_1"), StandardCharsets.UTF_8); sb.append(string+"&&"); }else { String[] split = sb.toString().split("&&"); String studentName = split[0]; String studentUsername = split[1]; String recruitInfoId = split[2]; String path=req.getServletContext().getRealPath("/"); String fieldName = studentName+"_"+studentUsername+"_"+recruitInfoId+"_"+item.getName(); String filePath = path+fieldName; resumeFile = fieldName; File file = new File(filePath); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); FileOutputStream fileOutputStream = new FileOutputStream(file); int line; while ((line = bufferedInputStream.read())!=-1){ fileOutputStream.write(line); } fileOutputStream.flush(); fileOutputStream.close(); bufferedInputStream.close(); } } String[] split = sb.toString().split("&&"); String studentName = split[0]; String studentUsername = split[1]; String recruitInfoId = split[2]; String applyPosition = split[3]; String phoneNum = split[4]; String email = split[5]; Resume resume = new Resume(studentUsername, Integer.parseInt(recruitInfoId), studentName, applyPosition, phoneNum, email, resumeFile); int insert = ResumeDao.insert(resume); if (insert == 1){ jsonObject.put("code",2000); jsonObject.put("msg","add success"); jsonObject.put("flag","success"); jsonObject.put("data",resume); resp.getWriter().print(jsonObject); return; }else { jsonObject.put("code",2000); jsonObject.put("msg","add fail"); jsonObject.put("flag","fail"); jsonObject.put("data",null); resp.getWriter().print(jsonObject); } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doGet(req, resp); } }
“Java兼職平臺系統(tǒng)如何實(shí)現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。