{"id":1281,"date":"2026-01-09T14:25:19","date_gmt":"2026-01-09T06:25:19","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1281"},"modified":"2026-01-09T14:25:19","modified_gmt":"2026-01-09T06:25:19","slug":"%e5%88%a9%e7%94%a8jspmysql%e5%ae%9e%e7%8e%b0%e5%a5%bd%e7%9c%8b%e7%9a%84%e7%99%bb%e5%bd%95%e4%b8%8e%e6%b3%a8%e5%86%8c%e9%a1%b5%e9%9d%a2%e5%8a%a8%e6%80%81%e8%83%8c%e6%99%af","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/09\/%e5%88%a9%e7%94%a8jspmysql%e5%ae%9e%e7%8e%b0%e5%a5%bd%e7%9c%8b%e7%9a%84%e7%99%bb%e5%bd%95%e4%b8%8e%e6%b3%a8%e5%86%8c%e9%a1%b5%e9%9d%a2%e5%8a%a8%e6%80%81%e8%83%8c%e6%99%af\/","title":{"rendered":"\u5229\u7528jsp+mysql\u5b9e\u73b0\u597d\u770b\u7684\u767b\u5f55\u4e0e\u6ce8\u518c\u9875\u9762(\u52a8\u6001\u80cc\u666f)"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u5957**\u300cJSP + MySQL \u5b9e\u73b0\u3010\u597d\u770b\u3011\u7684\u767b\u5f55 \/ \u6ce8\u518c\u9875\u9762\uff08\u542b\u52a8\u6001\u80cc\u666f\uff09\u300d\u5b8c\u6574\u5b9e\u6218\u65b9\u6848**\uff0c\u8fd9\u662f<strong>\u8bfe\u7a0b\u8bbe\u8ba1 \/ \u5b9e\u8bad \/ \u5c55\u793a\u7ea7\u522b<\/strong>\u7684\u505a\u6cd5\uff0c\u4e0d\u662f\u90a3\u79cd\u201c\u4e11 JSP\u201d\u3002<\/p>\n\n\n\n<p>\u7279\u70b9\ud83d\udc47<br>\u2705 JSP + Servlet + MySQL<br>\u2705 JDBC \u539f\u751f\u5b9e\u73b0\uff08\u8001\u5e08\u6700\u8ba4\u53ef\uff09<br>\u2705 <strong>\u52a8\u6001\u6e10\u53d8\u80cc\u666f \/ \u7c92\u5b50\u52a8\u753b\u80cc\u666f\uff08\u4e8c\u9009\u4e00\uff09<\/strong><br>\u2705 \u767b\u5f55 \/ \u6ce8\u518c\u5b8c\u6574\u95ed\u73af<br>\u2705 \u9875\u9762\u7f8e\u89c2\uff0c\u53ef\u76f4\u63a5\u622a\u56fe\u5f53\u6210\u679c<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u6700\u7ec8\u6548\u679c\u8bf4\u660e\uff08\u4f60\u505a\u51fa\u6765\u4f1a\u662f\u8fd9\u6837\uff09<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u767b\u5f55 \/ \u6ce8\u518c\u5361\u7247\u5c45\u4e2d<\/li>\n\n\n\n<li>\u534a\u900f\u660e\u6bdb\u73bb\u7483\u6548\u679c<\/li>\n\n\n\n<li>\u80cc\u666f <strong>\u52a8\u6001\u6e10\u53d8 \/ \u7c92\u5b50\u6d6e\u52a8<\/strong><\/li>\n\n\n\n<li>\u8868\u5355\u6821\u9a8c<\/li>\n\n\n\n<li>\u6570\u636e\u771f\u5b9e\u5b58\u5165 MySQL<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u9879\u76ee\u7ed3\u6784\uff08\u6807\u51c6 + \u6e05\u6670\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nLoginSystem\/\n\u2502\n\u251c\u2500\u2500 src\/\n\u2502   \u251c\u2500\u2500 entity\/\n\u2502   \u2502   \u2514\u2500\u2500 User.java\n\u2502   \u251c\u2500\u2500 util\/\n\u2502   \u2502   \u2514\u2500\u2500 DBUtil.java\n\u2502   \u251c\u2500\u2500 servlet\/\n\u2502   \u2502   \u251c\u2500\u2500 LoginServlet.java\n\u2502   \u2502   \u2514\u2500\u2500 RegisterServlet.java\n\u2502\n\u251c\u2500\u2500 WebContent\/\n\u2502   \u251c\u2500\u2500 css\/\n\u2502   \u2502   \u2514\u2500\u2500 style.css\n\u2502   \u251c\u2500\u2500 js\/\n\u2502   \u2502   \u2514\u2500\u2500 particles.min.js\n\u2502   \u251c\u2500\u2500 login.jsp\n\u2502   \u251c\u2500\u2500 register.jsp\n\u2502   \u2514\u2500\u2500 success.jsp\n\u2502\n\u2514\u2500\u2500 web.xml\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001MySQL \u6570\u636e\u5e93\u8bbe\u8ba1\uff08\u5fc5\u8003\u70b9\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u5efa\u5e93\u5efa\u8868<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE DATABASE jsp_login CHARACTER SET utf8;\n\nUSE jsp_login;\n\nCREATE TABLE user (\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    username VARCHAR(50) UNIQUE,\n    password VARCHAR(50)\n);\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u6570\u636e\u5e93\u5de5\u5177\u7c7b\uff08DBUtil.java\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npackage util;\n\nimport java.sql.*;\n\npublic class DBUtil {\n    private static final String URL =\n        &quot;jdbc:mysql:\/\/localhost:3306\/jsp_login?useUnicode=true&amp;amp;characterEncoding=utf8&quot;;\n    private static final String USER = &quot;root&quot;;\n    private static final String PASSWORD = &quot;123456&quot;;\n\n    static {\n        try {\n            Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n\n    public static Connection getConnection() throws SQLException {\n        return DriverManager.getConnection(URL, USER, PASSWORD);\n    }\n}\n\n<\/pre><\/div>\n\n\n<p>\u26a0\ufe0f \u6ce8\u610f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL 8 \u7528 <code>com.mysql.cj.jdbc.Driver<\/code><\/li>\n\n\n\n<li>\u8bb0\u5f97\u5bfc\u5165 <strong>mysql-connector-j.jar<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u6ce8\u518c\u9875\u9762\uff08register.jsp\uff09\u3010\u52a8\u6001\u80cc\u666f\u3011<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 HTML + CSS + \u52a8\u6001\u6e10\u53d8\u80cc\u666f<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; %&gt;\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html&gt;\n&amp;lt;head&gt;\n&amp;lt;title&gt;\u7528\u6237\u6ce8\u518c&amp;lt;\/title&gt;\n&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;css\/style.css&quot;&gt;\n&amp;lt;\/head&gt;\n&amp;lt;body&gt;\n\n&amp;lt;div class=&quot;bg&quot;&gt;&amp;lt;\/div&gt;\n\n&amp;lt;div class=&quot;login-box&quot;&gt;\n    &amp;lt;h2&gt;\u7528\u6237\u6ce8\u518c&amp;lt;\/h2&gt;\n    &amp;lt;form action=&quot;RegisterServlet&quot; method=&quot;post&quot;&gt;\n        &amp;lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;\u7528\u6237\u540d&quot; required&gt;\n        &amp;lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;\u5bc6\u7801&quot; required&gt;\n        &amp;lt;button type=&quot;submit&quot;&gt;\u6ce8\u518c&amp;lt;\/button&gt;\n    &amp;lt;\/form&gt;\n    &amp;lt;p&gt;&amp;lt;a href=&quot;login.jsp&quot;&gt;\u5df2\u6709\u8d26\u53f7\uff1f\u53bb\u767b\u5f55&amp;lt;\/a&gt;&amp;lt;\/p&gt;\n&amp;lt;\/div&gt;\n\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001CSS \u7f8e\u5316 + \u52a8\u6001\u80cc\u666f\uff08style.css\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n* {\n    margin: 0;\n    padding: 0;\n    font-family: &quot;Segoe UI&quot;;\n}\n\nbody, html {\n    width: 100%;\n    height: 100%;\n    overflow: hidden;\n}\n\n.bg {\n    position: fixed;\n    width: 100%;\n    height: 100%;\n    background: linear-gradient(-45deg,\n        #6a11cb, #2575fc, #ff512f, #dd2476);\n    background-size: 400% 400%;\n    animation: gradient 10s ease infinite;\n}\n\n@keyframes gradient {\n    0% {background-position: 0% 50%;}\n    50% {background-position: 100% 50%;}\n    100% {background-position: 0% 50%;}\n}\n\n.login-box {\n    position: absolute;\n    top: 50%;\n    left: 50%;\n    transform: translate(-50%, -50%);\n    width: 320px;\n    padding: 40px;\n    background: rgba(255,255,255,0.2);\n    backdrop-filter: blur(10px);\n    border-radius: 15px;\n    color: #fff;\n    text-align: center;\n}\n\n.login-box h2 {\n    margin-bottom: 20px;\n}\n\n.login-box input {\n    width: 100%;\n    padding: 10px;\n    margin: 10px 0;\n    border: none;\n    border-radius: 5px;\n}\n\n.login-box button {\n    width: 100%;\n    padding: 10px;\n    background: #fff;\n    border: none;\n    border-radius: 5px;\n    cursor: pointer;\n}\n\n<\/pre><\/div>\n\n\n<p>\ud83d\udccc <strong>\u8fd9\u5957 CSS \u975e\u5e38\u9002\u5408\u8bfe\u7a0b\u5c55\u793a\uff0c\u8001\u5e08\u4e00\u770b\u5c31\u52a0\u5206<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u6ce8\u518c Servlet\uff08RegisterServlet\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@WebServlet(&quot;\/RegisterServlet&quot;)\npublic class RegisterServlet extends HttpServlet {\n\n    protected void doPost(HttpServletRequest request, HttpServletResponse response)\n            throws IOException {\n\n        String username = request.getParameter(&quot;username&quot;);\n        String password = request.getParameter(&quot;password&quot;);\n\n        try (Connection conn = DBUtil.getConnection()) {\n            String sql = &quot;INSERT INTO user(username,password) VALUES (?,?)&quot;;\n            PreparedStatement ps = conn.prepareStatement(sql);\n            ps.setString(1, username);\n            ps.setString(2, password);\n            ps.executeUpdate();\n\n            response.sendRedirect(&quot;login.jsp&quot;);\n        } catch (Exception e) {\n            response.getWriter().write(&quot;\u6ce8\u518c\u5931\u8d25\uff0c\u7528\u6237\u540d\u5df2\u5b58\u5728&quot;);\n        }\n    }\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u767b\u5f55\u9875\u9762\uff08login.jsp\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; %&gt;\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html&gt;\n&amp;lt;head&gt;\n&amp;lt;title&gt;\u7528\u6237\u767b\u5f55&amp;lt;\/title&gt;\n&amp;lt;link rel=&quot;stylesheet&quot; href=&quot;css\/style.css&quot;&gt;\n&amp;lt;\/head&gt;\n&amp;lt;body&gt;\n\n&amp;lt;div class=&quot;bg&quot;&gt;&amp;lt;\/div&gt;\n\n&amp;lt;div class=&quot;login-box&quot;&gt;\n    &amp;lt;h2&gt;\u7528\u6237\u767b\u5f55&amp;lt;\/h2&gt;\n    &amp;lt;form action=&quot;LoginServlet&quot; method=&quot;post&quot;&gt;\n        &amp;lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;\u7528\u6237\u540d&quot; required&gt;\n        &amp;lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;\u5bc6\u7801&quot; required&gt;\n        &amp;lt;button type=&quot;submit&quot;&gt;\u767b\u5f55&amp;lt;\/button&gt;\n    &amp;lt;\/form&gt;\n    &amp;lt;p&gt;&amp;lt;a href=&quot;register.jsp&quot;&gt;\u6ca1\u6709\u8d26\u53f7\uff1f\u53bb\u6ce8\u518c&amp;lt;\/a&gt;&amp;lt;\/p&gt;\n&amp;lt;\/div&gt;\n\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u767b\u5f55 Servlet\uff08LoginServlet\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@WebServlet(&quot;\/LoginServlet&quot;)\npublic class LoginServlet extends HttpServlet {\n\n    protected void doPost(HttpServletRequest request, HttpServletResponse response)\n            throws IOException {\n\n        String username = request.getParameter(&quot;username&quot;);\n        String password = request.getParameter(&quot;password&quot;);\n\n        try (Connection conn = DBUtil.getConnection()) {\n            String sql = &quot;SELECT * FROM user WHERE username=? AND password=?&quot;;\n            PreparedStatement ps = conn.prepareStatement(sql);\n            ps.setString(1, username);\n            ps.setString(2, password);\n\n            ResultSet rs = ps.executeQuery();\n\n            if (rs.next()) {\n                request.getSession().setAttribute(&quot;user&quot;, username);\n                response.sendRedirect(&quot;success.jsp&quot;);\n            } else {\n                response.getWriter().write(&quot;\u7528\u6237\u540d\u6216\u5bc6\u7801\u9519\u8bef&quot;);\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u3001\u767b\u5f55\u6210\u529f\u9875\u9762\uff08success.jsp\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; %&gt;\n&amp;lt;html&gt;\n&amp;lt;body&gt;\n&amp;lt;h2&gt;\u767b\u5f55\u6210\u529f\uff01&amp;lt;\/h2&gt;\n\u6b22\u8fce\u4f60\uff1a${sessionScope.user}\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u4e00\u3001\u5168\u8fc7\u7a0b\u603b\u7ed3\uff08\u8003\u8bd5\u5fc5\u80cc\uff09<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>JSP \u63d0\u4f9b\u9875\u9762\u5c55\u793a<\/li>\n\n\n\n<li>CSS \u5b9e\u73b0\u52a8\u6001\u80cc\u666f\u4e0e\u7f8e\u5316<\/li>\n\n\n\n<li>\u8868\u5355\u63d0\u4ea4\u7ed9 Servlet<\/li>\n\n\n\n<li>Servlet \u4f7f\u7528 JDBC \u64cd\u4f5c MySQL<\/li>\n\n\n\n<li>\u767b\u5f55\u6210\u529f \u2192 Session \u4fdd\u5b58\u7528\u6237\u4fe1\u606f<\/li>\n\n\n\n<li>\u9875\u9762\u8df3\u8f6c<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u4e8c\u3001\u8fd8\u80fd\u7ee7\u7eed\u5347\u7ea7\uff08\u76f4\u63a5\u62c9\u6ee1\uff09<\/h2>\n\n\n\n<p>\ud83d\udd25 \u7c92\u5b50\u80cc\u666f\uff08particles.js\uff09<br>\ud83d\udd25 \u5bc6\u7801\u52a0\u5bc6\uff08MD5 \/ BCrypt\uff09<br>\ud83d\udd25 \u9a8c\u8bc1\u7801<br>\ud83d\udd25 \u767b\u5f55\u62e6\u622a\u5668 Filter<br>\ud83d\udd25 \u524d\u540e\u7aef\u5206\u79bb\uff08Vue + Spring Boot\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u5957**\u300cJSP + MySQL \u5b9e\u73b0\u3010\u597d\u770b\u3011\u7684\u767b\u5f55 \/ \u6ce8\u518c\u9875\u9762\uff08\u542b\u52a8&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/01\/09\/%e5%88%a9%e7%94%a8jspmysql%e5%ae%9e%e7%8e%b0%e5%a5%bd%e7%9c%8b%e7%9a%84%e7%99%bb%e5%bd%95%e4%b8%8e%e6%b3%a8%e5%86%8c%e9%a1%b5%e9%9d%a2%e5%8a%a8%e6%80%81%e8%83%8c%e6%99%af\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-1281","post","type-post","status-publish","format-standard","hentry","category-jsp"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1281"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1281\/revisions"}],"predecessor-version":[{"id":1282,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1281\/revisions\/1282"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}