{"id":8300,"date":"2024-04-24T11:01:01","date_gmt":"2024-04-24T03:01:01","guid":{"rendered":""},"modified":"2024-04-24T11:01:01","modified_gmt":"2024-04-24T03:01:01","slug":"JAVA-SUST\u5b9e\u9a8c\u4e8c JavaBean\u7ec4\u4ef6\u7a0b\u5e8f\u8bbe\u8ba1","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8300.html","title":{"rendered":"JAVA-SUST\u5b9e\u9a8c\u4e8c JavaBean\u7ec4\u4ef6\u7a0b\u5e8f\u8bbe\u8ba1"},"content":{"rendered":"
1\u3001\u7406\u89e3 JavaBean \u7684\u4f5c\u7528\uff1b<\/strong><\/span><\/p>\n 2\u3001\u80fd\u591f\u5b9a\u4e49 JavaBean\uff1b<\/strong><\/span><\/p>\n 3\u3001\u80fd\u5728 JSP \u9875\u9762\u4e2d\u4f7f\u7528 JavaBean\u3002<\/strong><\/span><\/p>\n 1\u3001\u5b9e\u73b0\u529f\u80fd\u8bf4\u660e\uff1a\u4ee5\u7528\u6237\u6ce8\u518c\u4fe1\u606f\u9875\u9762\u4e3a\u4f8b\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7528\u6237\u4fe1\u606f JavaBean \u5e76\u5728JSP\u9875\u9762\u4e2d\u901a\u8fc7jsp\u4e2d\u901a\u8fc7\u76f4\u63a5\u8bbf\u95ee\u6216\u6807\u7b7e\u4e24\u79cd\u5f62\u5f0f\u8fdb\u884c\u8c03\u7528\u3002\u5b9e\u73b0\u4e0b\u5217\u529f\u80fd\uff1a<\/strong><\/span><\/p>\n (a)\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u6ce8\u518c\u4fe1\u606f\u8f93\u5165\u9875\u9762\uff0c\u7528\u6237\u8f93\u5165\u4fe1\u606f\u5305\u62ec\uff1a\u59d3\u540d\u3001\u5b66\u53f7\u3001\u767b\u5f55\u5bc6\u7801\u3001\u6027\u522b\u3001\u5e74\u9f84\u3001\u7c4d\u8d2f\u3001\u9009\u4fee\u8bfe\u7a0b\u4ee5\u53ca\u4e2a\u4eba\u7b80\u4ecb\uff0c\u5176\u4e2d\u6027\u522b\u4e3a\u5e03\u5c14\u503c\u3001\u9009\u4fee\u8bfe\u7a0b\u4e3a\u591a\u9009\uff1b<\/strong><\/span><\/p>\n (b)\u5b9a\u4e49\u7528\u6237\u4fe1\u606fJavaBean\uff0c\u5176\u5185\u5bb9\u4e0e\u7528\u6237\u6ce8\u518c\u8868\u5355\u76f8\u4e00\u81f4\uff1b<\/strong><\/span><\/p>\n (c)\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u4fe1\u606f\u4fdd\u6301\u9875\u9762\uff0c\u5728JSP\u4e2d\u4f7f\u7528\u6807\u7b7e\u5f62\u5f0f\uff0c\u6839\u636e\u524d\u4e00\u4e2a\u9875\u9762\u63d0\u4ea4\u7684\u6ce8\u518c\u4fe1\u606f\u6784\u9020\u7528\u6237\u4fe1\u606fJavaBean\u5bf9\u8c61\uff0c\u6ce8\u610f\u8bbe\u7f6e\u5176\u4f5c\u7528\u8303\u56f4\uff1b<\/strong><\/span><\/p>\n (d)\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u767b\u5f55\u4ee5\u53ca\u9a8c\u8bc1\u9875\u9762\uff0c\u7528\u6237\u901a\u8fc7\u8f93\u5165\u59d3\u540d\u548c\u5bc6\u7801\u6765\u8fdb\u884c\u7cfb\u7edf\u767b\u5f55\uff0c\u5f53\u7528\u6237\u540d\u548c\u5bc6\u7801\u4e0eJavaBean\u4e2d\u7684\u4fe1\u606f\u4e00\u81f4\u65f6\u5141\u8bb8\u767b\u5f55\uff0c\u5426\u5219\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u6216\u8f6c\u5411\u9519\u8bef\u9875\u9762\u3002<\/strong><\/span><\/p>\n 2\u3001\u5b9e\u9a8c\u8981\u6c42\uff1a\u8bbe\u8ba1\u4ee3\u7801\u9a8c\u8bc1\u4e0a\u8ff0\u65b9\u6cd5\u5e76\u8c03\u8bd5\u7a0b\u5e8f\u662f\u5426\u6b63\u5e38\u8fd0\u884c<\/strong><\/span><\/p>\n <\/strong><\/span><\/p>\n <\/strong><\/span><\/p>\n <\/strong><\/span><\/p>\n <\/strong><\/span><\/p>\n <\/strong><\/span><\/p>\n <\/p>\n **********************<\/strong><\/span><\/p>\n **********************<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"JAVA-SUST\u5b9e\u9a8c\u4e8c JavaBean\u7ec4\u4ef6\u7a0b\u5e8f\u8bbe\u8ba1\u4e00\u3001\u5b9e\u9a8c\u76ee\u76841\u3001\u7406\u89e3JavaBean\u7684\u4f5c\u7528\uff1b2\u3001\u80fd\u591f\u5b9a\u4e49JavaBean\uff1b3\u3001\u80fd\u5728JSP\u9875\u9762\u4e2d\u4f7f\u7528JavaBean","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\/8300"}],"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=8300"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8300\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u4e8c\u3001\u5b9e\u9a8c\u5185\u5bb9<\/strong><\/span><\/h2>\n
\u4e09\u3001\u5b9e\u9a8c\u6b65\u9aa4\u53ca\u5b9e\u9a8c\u7ed3\u679c\u8bb0\u5f55<\/strong><\/span><\/h2>\n
1. \u9996\u9875<\/strong><\/span><\/h3>\n
2. \u6ce8\u518c<\/strong><\/span><\/h3>\n
3. \u6ce8\u518c\u4fe1\u606f\u5c55\u793a<\/strong><\/span><\/h3>\n
4. \u767b\u5f55<\/strong><\/span><\/h3>\n
5. \u767b\u5f55\u5931\u8d25<\/strong><\/span><\/h3>\n
6. \u767b\u5f55\u6210\u529f<\/strong><\/span><\/h3>\n
\u56db\u3001\u6838\u5fc3\u6e90\u4ee3\u7801\uff08\u8be6\u7ec6\u4ee3\u7801\u89c1\u7535\u5b50\u6587\u6863\uff09<\/strong><\/span><\/h3>\n
\u5b66\u751fStudent.java<\/strong><\/span><\/h3>\n
package com.suke;\n\npublic class Student {\n\n private int id;\/\/\u5b66\u53f7\n\n private String name; \/\/\u59d3\u540d\n\n private String password;\/\/\u5bc6\u7801\n\n private int age;\/\/\u5e74\u9f84\n\n private String gender;\/\/\u6027\u522b\n\n private String address;\/\/\u7c4d\u8d2f\n\n private String[] course;\/\/\u9009\u4fee\u8bfe\u7a0b\n\n private String profile;\/\/\u9694\u4e2a\u4eba\u7b80\u4ecb\n\n\n public Student() {\n\n }\n\n\n public Student(int id, String name, String password, int age, String gender, String address, String[] course, String profile) {\n\n this.id = id;\n\n this.name = name;\n\n this.password = password;\n\n this.age = age;\n\n this.gender = gender;\n\n this.address = address;\n\n this.course = course;\n\n this.profile = profile;\n\n }\n\n\n public int getId() {\n\n return id;\n\n }\n\n\n public void setId(int id) {\n\n this.id = id;\n\n }\n\n\n public String getName() {\n\n return name;\n\n }\n\n\n public void setName(String name) {\n\n this.name = name;\n\n }\n\n\n public String getPassword() {\n\n return password;\n\n }\n\n\n public void setPassword(String password) {\n\n this.password = password;\n\n }\n\n\n public int getAge() {\n\n return age;\n\n }\n\n\n public void setAge(int age) {\n\n this.age = age;\n\n }\n\n\n public String getGender() {\n\n return gender;\n\n }\n\n\n public void setGender(String gender) {\n\n this.gender = gender;\n\n }\n\n\n public String getAddress() {\n\n return address;\n\n }\n\n\n public void setAddress(String address) {\n\n this.address = address;\n\n }\n\n\n public String[] getCourse() {\n\n return course;\n\n }\n\n\n public void setCourse(String[] course) {\n\n this.course = course;\n\n }\n\n\n public String getProfile() {\n\n return profile;\n\n }\n\n\n public void setProfile(String profile) {\n\n this.profile = profile;\n\n }\n\n}<\/code><\/pre>\n
\u9996\u9875index.jsp<\/strong><\/span><\/h3>\n
<\/h3>\n
<%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n\n<html>\n\n<head>\n\n <title>\u9996\u9875<\/title>\n\n<\/head>\n\n<body>\n\n<form action=\"logon.jsp\" method=\"post\">\n\n <input type=\"submit\" value=\"\u6ce8\u518c\">\n\n<\/form>\n\n<br>\n\n<form action=\"login.jsp\" method=\"post\">\n\n <input type=\"submit\" value=\"\u767b\u5f55\">\n\n<\/form>\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u6ce8\u518clogon.jsp<\/strong><\/span><\/h3>\n
<%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n\n<html>\n\n<head>\n\n <title>\u6ce8\u518c<\/title>\n\n<\/head>\n\n<body>\n\n<jsp:useBean id=\"student\" class=\"com.suke.Student\" scope=\"page\">\n\n <form action=\"showInfo.jsp\" method=\"post\">\n\n <table>\n\n <tr>\n\n <td>\u59d3\u540d\uff1a<\/td>\n\n <td><input type=\"text\" name=\"name\"\/><\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u5b66\u53f7\uff1a<\/td>\n\n <td><input type=\"text\" name=\"id\"\/><\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u5bc6\u7801\uff1a<\/td>\n\n <td><input type=\"password\" name=\"password\"\/><\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u6027\u522b\uff1a<\/td>\n\n <td><input type=\"radio\" name=\"gender\" value=\"\u7537\"\/>\u7537\n\n <input type=\"radio\" name=\"gender\" value=\"\u5973\"\/>\u5973\n\n <\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u5e74\u9f84\uff1a<\/td>\n\n <td><input type=\"text\" name=\"age\"\/><\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u7c4d\u8d2f\uff1a<\/td>\n\n <td><input type=\"text\" name=\"address\"\/><\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u9009\u4fee\u8bfe\u7a0b\uff1a<\/td>\n\n <td><input type=\"checkbox\" name=\"course\" value=\"Java\"\/>Java\n\n <input type=\"checkbox\" name=\"course\" value=\"Python\"\/>Python\n\n <input type=\"checkbox\" name=\"course\" value=\"Linux\"\/>Linux\n\n <input type=\"checkbox\" name=\"course\" value=\"Vue\"\/>Vue\n\n <\/td>\n\n <\/tr>\n\n <tr>\n\n <td>\u4e2a\u4eba\u7b80\u4ecb\uff1a<\/td>\n\n <td><textarea rows=\"5\" cols=\"15\" name=\"profile\"><\/textarea><\/td>\n\n <\/tr>\n\n <tr>\n\n <td><input type=\"submit\" value=\"\u6ce8\u518c\"\/><\/td>\n\n <\/tr>\n\n <\/table>\n\n <\/form>\n\n<\/jsp:useBean>\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u6ce8\u518c\u4fe1\u606f\u5c55\u793ashowInfo.jsp<\/strong><\/span><\/h3>\n
<%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\"\n\n pageEncoding=\"UTF-8\" %>\n\n<!DOCTYPE html>\n\n<html>\n\n<head>\n\n <meta charset=\"UTF-8\">\n\n <title>Insert title here<\/title>\n\n<\/head>\n\n<body>\n\n<%\n\n request.setCharacterEncoding(\"UTF-8\");\n\n%>\n\n<jsp:useBean id=\"student\" class=\"com.suke.Student\" scope=\"page\">\n\n <jsp:setProperty name=\"student\" property=\"*\"\/>\n\n \u59d3\u540d\uff1a\n\n <jsp:getProperty name=\"student\" property=\"name\"\/>\n\n <br\/>\n\n \u5b66\u53f7\uff1a\n\n <jsp:getProperty name=\"student\" property=\"id\"\/>\n\n <br\/>\n\n \u5bc6\u7801\uff1a\n\n <jsp:getProperty name=\"student\" property=\"password\"\/>\n\n <br\/>\n\n \u6027\u522b\uff1a\n\n <jsp:getProperty name=\"student\" property=\"gender\"\/>\n\n <br\/>\n\n \u5e74\u9f84\uff1a\n\n <jsp:getProperty name=\"student\" property=\"age\"\/>\n\n <br\/>\n\n \u7c4d\u8d2f\uff1a\n\n <jsp:getProperty name=\"student\" property=\"address\"\/>\n\n <br\/>\n\n \u9009\u4fee\u8bfe\u7a0b\uff1a\n\n <%\n\n String[] course = student.getCourse();\n\n if (course != null) {\n\n for (int i = 0; i < course.length; i++) {\n\n out.print(course[i] + \" \");\n\n }\n\n }\n\n %><br\/>\n\n \u4e2a\u4eba\u7b80\u4ecb\uff1a\n\n <jsp:getProperty name=\"student\" property=\"profile\"\/>\n\n<\/jsp:useBean>\n\n<br\/>\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u767b\u5f55login.jsp<\/strong><\/span><\/h3>\n
<%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n\n<!DOCTYPE html>\n\n<html lang=\"en\">\n\n<head>\n\n <meta charset=\"UTF-8\">\n\n <title>\u767b\u5f55<\/title>\n\n<\/head>\n\n<body>\n\n<form action=\"checkLogin.jsp\" method=\"post\">\n\n \u59d3\u540d\uff1a<input type=\"text\" name=\"name\"><br>\n\n \u5bc6\u7801\uff1a<input type=\"password\" name=\"password\"><br>\n\n <input type=\"submit\" value=\"\u767b\u5f55\">\n\n<\/form>\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u767b\u5f55\u5931\u8d25failLogin.jsp<\/strong><\/span><\/h3>\n
<%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n\n<!DOCTYPE html>\n\n<html>\n\n<head>\n\n <meta charset=\"UTF-8\">\n\n <title>Insert title here<\/title>\n\n<\/head>\n\n<body>\n\n<h2>\u8d26\u53f7\u9762\u6709\u8bef\uff0c\u767b\u5f55\u5931\u8d25<\/h2>\n\n<a href=\"login.jsp\">\u91cd\u65b0\u767b\u5f55<\/a>\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u767b\u5f55\u6210\u529fsuccessLogin.jsp<\/strong><\/span><\/h3>\n
<%@ page contentType=\"text\/html;charset=UTF-8\" language=\"java\" %>\n\n<html>\n\n<head>\n\n <title>\u767b\u5f55<\/title>\n\n<\/head>\n\n<body>\n\n<%=request.getParameter(\"name\")%>\u767b\u5f55\u6210\u529f\uff01\n\n<\/body>\n\n<\/html><\/code><\/pre>\n
\u4e94\u3001\u5b9e\u9a8c\u603b\u7ed3<\/strong><\/span><\/h2>\n