{"id":6205,"date":"2024-08-15T17:01:01","date_gmt":"2024-08-15T09:01:01","guid":{"rendered":""},"modified":"2024-08-15T17:01:01","modified_gmt":"2024-08-15T09:01:01","slug":"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfb","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6205.html","title":{"rendered":"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfb"},"content":{"rendered":"
\n

JSP\u663e\u793a\u65b0\u95fb<\/p>\n

1\u3001\u9879\u76ee\u7ed3\u6784<\/p>\n

java\uff1a<\/p>\n

\"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfb<\/p>\n

Web\uff1a<\/p>\n

\"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfb<\/p>\n

2\u3001Java\u90e8\u5206\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n

2.1 Controller<\/p>\n

\"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfb<\/p>\n

LoginServlet\uff1a<\/p>\n

\u7528\u6765\u83b7\u53d6\u7f51\u7ad9\u7684\u767b\u5f55\u4fe1\u606f\uff0c\u5e76\u4f20\u7ed9UsersService\u8fdb\u884c\u5904\u7406\u5224\u65ad<\/p>\n

1 packageController;2<\/p>\n

3 importEntity.Users;4 importService.UsersService;5 importUtil.CookieSave;6 importjavax.servlet.ServletException;7 importjavax.servlet.annotation.WebServlet;8 importjavax.servlet.http.HttpServlet;9 importjavax.servlet.http.HttpServletRequest;10 importjavax.servlet.http.HttpServletResponse;11 importjava.io.IOException;12 importjava.sql.SQLException;13<\/p>\n

14 @WebServlet(name = \"Controller.LoginServlet\")15 public class LoginServlet extendsHttpServlet {16 protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsIOException, ServletException {17 doGet(request,response);18 }19 protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {20 response.setContentType(\"text\/html;charset=utf-8\");21 request.setCharacterEncoding(\"utf-8\");22 \/\/Login\u7684\u5904\u7406<\/p>\n

23 try{24 Login(request,response);25 } catch(SQLException e) {26 e.printStackTrace();27 }28 }29 void Login(HttpServletRequest request, HttpServletResponse response) throwsIOException, SQLException {30 \/\/\u83b7\u53d6\u8868\u5355\u4e2d\u7684\u6570\u636e\u7684\u503c<\/p>\n

31 Users user=newUsers();32 user.setName(request.getParameter(\"username\"));33 user.setPassword(request.getParameter(\"password\"));34 System.out.println(\"\u767b\u5165\u7528\u6237\u540d\uff1a\"+user.getName());35 System.out.println(\"\u767b\u5165\u7528\u6237\u5bc6\u7801\uff1a\"+user.getPassword());36 System.out.println(\"-------------------------------\");37 \/\/\u9a8c\u8bc1\u7528\u6237\u540d\u5bc6\u7801<\/p>\n

38 UsersService usersService=newUsersService();39 boolean hasUsers=usersService.QueryUsers(user);40 if(hasUsers){41 CookieSave cookieSave=newCookieSave();42 cookieSave.Save(response,\"username\",user.getName(),60*60*24*30);43 cookieSave.Save(response,\"password\",user.getPassword(),60*60*24*30);44 \/\/\u6210\u529f\u767b\u5f55<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"jsp\u5982\u4f55\u505a\u65b0\u95fb\u53d1\u5e03\u9875\u9762_jsp\u548cjava\u4ec0\u4e48\u5173\u7cfbJSP\u663e\u793a\u65b0\u95fb1\u3001\u9879\u76ee\u7ed3\u6784java\uff1aWeb\uff1a2\u3001Java\u90e8\u5206\u8be6\u7ec6\u4ecb\u7ecd2.1ControllerLoginServlet...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6205"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6205"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6205\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}