├── Db └── DbUtil.java ├── LICENSE ├── README.md ├── bean ├── Book.java ├── Info.java ├── Manager.java └── Student.java ├── dao ├── IBookDao.java ├── IInfoDao.java ├── IManagerDao.java └── IStudentDao.java ├── factory └── DaoFactory.java ├── impl ├── BookDaoImpl.java ├── InfoDaoImpl.java ├── ManagerDaoImpl.java └── StudentDaoImpl.java ├── library.sql ├── service └── UserManager.java ├── servlet ├── ActiveServlet.java ├── AddBook.java ├── AddOneStudent.java ├── BorrowBook.java ├── ChangeAdminPwd.java ├── DeleteBook.java ├── Exit.java ├── ExportBookInfo.java ├── FenYe.java ├── HuanShu.java ├── ImportStudentFromExcel.java ├── LoginCheck.java ├── RegisterAdmin.java ├── SelectAllBook.java ├── SelectBorrowinfo.java ├── SetEncoding.java └── ShowBookInfo.java ├── tool ├── DesUtils.java ├── GetBookData.java ├── GetStudentData.java └── SendMail.java └── 数据库代码及sql文件.zip /Db/DbUtil.java: -------------------------------------------------------------------------------- 1 | package com.henu.Db; 2 | 3 | import java.sql.*; 4 | 5 | public class DbUtil { 6 | private static final String URL="jdbc:mysql://localhost:3306/library?serverTimezone=UTC&useSSL=true"; 7 | private static final String USER = "root"; 8 | private static final String PASSWORD = "282798"; 9 | 10 | protected static Statement s = null; 11 | protected static ResultSet rs = null; 12 | protected static Connection conn = null; 13 | 14 | public static synchronized Connection getConnection(){ 15 | try { 16 | Class.forName("com.mysql.cj.jdbc.Driver"); 17 | conn = DriverManager.getConnection(URL,USER,PASSWORD); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | 22 | return conn; 23 | } 24 | 25 | public static int executeUpdate(String sql){ 26 | int result = 0; 27 | try { 28 | s = getConnection().createStatement(); 29 | result = s.executeUpdate(sql); 30 | } catch (SQLException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | return result; 35 | } 36 | 37 | public static ResultSet executeQuery(String sql){ 38 | try { 39 | s = getConnection().createStatement(); 40 | rs = s.executeQuery(sql); 41 | } catch (SQLException e) { 42 | e.printStackTrace(); 43 | } 44 | 45 | return rs; 46 | } 47 | 48 | public static PreparedStatement executePreparedStatement(String sql){ 49 | PreparedStatement ps = null; 50 | try { 51 | ps = getConnection().prepareStatement(sql); 52 | } catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | return ps; 57 | } 58 | 59 | public static void rollback(){ 60 | try { 61 | getConnection().rollback(); 62 | } catch (SQLException e) { 63 | e.printStackTrace(); 64 | } 65 | } 66 | 67 | public static void close(){ 68 | try { 69 | if(rs != null) 70 | rs.close(); 71 | if(s != null) 72 | s.close(); 73 | if(conn != null) 74 | conn.close(); 75 | } catch (SQLException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 图书管理与借阅系统 2 | 3 | ## 概述 4 | 5 | 一款简洁的图书管理与借阅系统,分为管理员和借阅者模式。 6 | 7 | 管理员模式具有对图书信息和学生信息的增删改查、对图书信息的导入和导出、增加管理员和修改管理员密码功能。 8 | 9 | 借阅者模式具有借书和还书的功能。 10 | 11 | **演示地址:** 12 | 13 | https://dbtest.wangfuchao.com/ 14 | 15 | 测试管理员账户:admin 16 | 17 | 测试管理员密码:admin 18 | 19 | **预览:** 20 | 21 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117215903.png) 22 | 23 | ## 技术栈 24 | 25 | Servlet + Jsp + Tomcat + MySQL 26 | 27 | ## 表结构 28 | 29 | | 表名 | 中文含义 | 介绍 | 30 | | ------- | -------- | ------------------------------------------------ | 31 | | book | 图书表 | 存放图书信息,如书名、作者、出版社、出版日期等。 | 32 | | borrow | 借书表 | 存放借书信息,如借阅者id、借阅书名、借阅日期等。 | 33 | | manager | 管理员表 | 存放管理员信息等 | 34 | | student | 学生表 | 存放学生信息,如学生id、学生姓名、学生性别等。 | 35 | 36 | Book表: 37 | 38 | | bookname | author | press | pubdate | type | bookshelf | count | 39 | | -------- | ------ | ----- | ------- | ---- | --------- | ----- | 40 | | | | | | | | | 41 | 42 | Borrow表: 43 | 44 | | id | bookname | type | date | days | count | 45 | | ---- | -------- | ---- | ---- | ---- | ----- | 46 | | | | | | | | 47 | 48 | Manager表: 49 | 50 | | username | password | islogin | code | state | 51 | | -------- | -------- | ------- | ---- | ----- | 52 | | | | | | | 53 | 54 | Student表: 55 | 56 | | id | name | gender | phone | email | department | islogin | 57 | | ---- | ---- | ------ | ----- | ----- | ---------- | ------- | 58 | | | | | | | | | 59 | 60 | ## ERD 61 | 62 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220208.png) 63 | 64 | ## 系统功能截图 65 | 66 | 登陆界面: 67 | 68 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220259.png) 69 | 70 | 管理员界面首页: 71 | 72 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220317.png) 73 | 74 | 学生信息管理界面: 75 | 76 | 可查看学生信息和图书借阅情况,并且可以单个导入或者使用excel表格批量导入学生。 77 | 78 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220341.png) 79 | 80 | 图书信息管理界面: 81 | 82 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220354.png) 83 | 84 | 添加图书功能: 85 | 86 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220408.png) 87 | 88 | 修改管理员密码: 89 | 90 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220510.png) 91 | 92 | 添加管理员: 93 | 94 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220527.png) 95 | 96 | 用户退出: 97 | 98 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220538.png) 99 | 100 | 借阅者登录界面: 101 | 102 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220626.png) 103 | 104 | 借阅信息: 105 | 106 | 可在此界面还书 107 | 108 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220646.png) 109 | 110 | 借书功能: 111 | 112 | ![](https://cdn.jsdelivr.net/gh/sduwfc/pic/20210117220658.png) 113 | -------------------------------------------------------------------------------- /bean/Book.java: -------------------------------------------------------------------------------- 1 | package com.henu.bean; 2 | 3 | import java.sql.Date; 4 | 5 | public class Book { 6 | private String bookname; //书名 7 | private String author; //作者 8 | private String press; //出版社 9 | private String pubdate; //出版时间 10 | private String type; //类型 11 | private String bookshelf; //书架 12 | private int count; //数量 13 | 14 | public Book(){} 15 | 16 | public Book(String bookname,String author,String press,String pubdate,String type,String bookshelf,int count){ 17 | this.bookname = bookname; 18 | this.author = author; 19 | this.press = press; 20 | this.pubdate = pubdate; 21 | this.type = type; 22 | this.bookshelf = bookshelf; 23 | this.count = count; 24 | } 25 | 26 | public String getBookname() { 27 | return bookname; 28 | } 29 | 30 | public void setBookname(String bookname) { 31 | this.bookname = bookname; 32 | } 33 | 34 | public String getAuthor() { 35 | return author; 36 | } 37 | 38 | public void setAuthor(String author) { 39 | this.author = author; 40 | } 41 | 42 | public String getPress() { 43 | return press; 44 | } 45 | 46 | public void setPress(String press) { 47 | this.press = press; 48 | } 49 | 50 | public String getPubdate() { 51 | return pubdate; 52 | } 53 | 54 | public void setPubdate(String pubdate) { 55 | this.pubdate = pubdate; 56 | } 57 | 58 | public String getType() { 59 | return type; 60 | } 61 | 62 | public void setType(String type) { 63 | this.type = type; 64 | } 65 | 66 | public String getBookshelf() { 67 | return bookshelf; 68 | } 69 | 70 | public void setBookshelf(String bookshelf) { 71 | this.bookshelf = bookshelf; 72 | } 73 | 74 | public int getCount() { 75 | return count; 76 | } 77 | 78 | public void setCount(int count) { 79 | this.count = count; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /bean/Info.java: -------------------------------------------------------------------------------- 1 | package com.henu.bean; 2 | 3 | 4 | public class Info { 5 | private String id; //学号 6 | private String bookname; //书名 7 | private String type; //类型 8 | private String date; //借书日期 9 | private int days; //借阅天数 10 | private int Con; //借阅数量 11 | 12 | public Info(){} 13 | 14 | public Info(String id,String bookname,String type,String date,int days,int cou){ 15 | this.id = id; 16 | this.bookname = bookname; 17 | this.type = type; 18 | this.date = date; 19 | this.days = days; 20 | this.Con = cou; 21 | } 22 | public String getId() { 23 | return id; 24 | } 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | public String getBookname() { 29 | return bookname; 30 | } 31 | public void setBookname(String bookname) { 32 | this.bookname = bookname; 33 | } 34 | public String getType() { 35 | return type; 36 | } 37 | public void setType(String type) { 38 | this.type = type; 39 | } 40 | public String getDate() { 41 | return date; 42 | } 43 | public void setDate(String date) { 44 | this.date = date; 45 | } 46 | public int getCon() { 47 | return Con; 48 | } 49 | public void setCon(int con) { 50 | Con = con; 51 | } 52 | public int getDays() { 53 | return days; 54 | } 55 | public void setDays(int days) { 56 | this.days = days; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /bean/Manager.java: -------------------------------------------------------------------------------- 1 | package com.henu.bean; 2 | 3 | public class Manager { 4 | private String username; 5 | private String password; 6 | private int islogin; 7 | public String getCode() { 8 | return code; 9 | } 10 | 11 | public void setCode(String code) { 12 | this.code = code; 13 | } 14 | 15 | public String getState() { 16 | return state; 17 | } 18 | 19 | public void setState(String state) { 20 | this.state = state; 21 | } 22 | 23 | private String code; 24 | private String state; 25 | 26 | public int getIslogin() { 27 | return islogin; 28 | } 29 | 30 | public void setIslogin(int islogin) { 31 | this.islogin = islogin; 32 | } 33 | 34 | public Manager(){} 35 | 36 | public Manager(String username,String password,int islogin,String code,String state){ 37 | this.username = username; 38 | this.password=password; 39 | this.islogin = islogin; 40 | this.code = code; 41 | this.state = state; 42 | } 43 | 44 | public String getUsername() { 45 | return username; 46 | } 47 | 48 | public void setUsername(String username) { 49 | this.username = username; 50 | } 51 | 52 | public String getPassword() { 53 | return password; 54 | } 55 | 56 | public void setPassword(String password) { 57 | this.password = password; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /bean/Student.java: -------------------------------------------------------------------------------- 1 | package com.henu.bean; 2 | 3 | public class Student { 4 | private String id; //学号 5 | private String name; //姓名 6 | private String gender; //性别 7 | private String phone; //电话 8 | private String email; //邮箱 9 | private String department; //学院 10 | private int islogin; //是否登录 11 | public Student(){}; 12 | public Student(String id,String name,String gender,String phone,String email,String department,int islogin){ 13 | this.id = id; 14 | this.name = name; 15 | this.gender = gender; 16 | this.phone = phone; 17 | this.email = email; 18 | this.department = department; 19 | this.islogin = islogin; 20 | } 21 | public int getIslogin() { 22 | return islogin; 23 | } 24 | public void setIslogin(int islogin) { 25 | this.islogin = islogin; 26 | } 27 | public String getId() { 28 | return id; 29 | } 30 | public void setId(String id) { 31 | this.id = id; 32 | } 33 | public String getName() { 34 | return name; 35 | } 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | public String getGender() { 40 | return gender; 41 | } 42 | public void setGender(String gender) { 43 | this.gender = gender; 44 | } 45 | public String getPhone() { 46 | return phone; 47 | } 48 | public void setPhone(String phone) { 49 | this.phone = phone; 50 | } 51 | public String getEmail() { 52 | return email; 53 | } 54 | public void setEmail(String email) { 55 | this.email = email; 56 | } 57 | public String getDepartment() { 58 | return department; 59 | } 60 | public void setDepartment(String department) { 61 | this.department = department; 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /dao/IBookDao.java: -------------------------------------------------------------------------------- 1 | package com.henu.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.henu.bean.Book; 6 | 7 | public interface IBookDao { 8 | 9 | 10 | 11 | /** 12 | * 根据书名查询书籍 13 | * @param bookname 14 | * @return 15 | */ 16 | public Book book(String bookname); 17 | 18 | /** 19 | * 判断书籍数量是否足够 20 | * @param bookname 书名 21 | * @param count 借阅数量 22 | * @return 23 | */ 24 | public boolean isEnough(String bookname,int count); 25 | 26 | /** 27 | * 更改图书的数量(借书还书后的数量) 28 | * @param bookname 书名 29 | * @param count 借书或还书的数量 30 | * @param type 类型(借书还是还书) 31 | * @return 32 | */ 33 | public int changeCount(String bookname,int count,String type); 34 | 35 | /** 36 | * 添加图书 37 | * @param book 38 | * @return 39 | */ 40 | public int addBook(Book book); 41 | 42 | /** 43 | * 查询所有图书信息 44 | * @return 45 | */ 46 | public List selectAllBook(); 47 | 48 | /** 49 | * 删除书籍 50 | * @param bookname 51 | * @return 52 | */ 53 | public int deleteBook(String bookname); 54 | } 55 | -------------------------------------------------------------------------------- /dao/IInfoDao.java: -------------------------------------------------------------------------------- 1 | package com.henu.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.henu.bean.Info; 6 | 7 | public interface IInfoDao { 8 | 9 | /** 10 | * 根据id和bookname删除该条信息 11 | * @param id 12 | * @param bookname 13 | * @return 14 | */ 15 | public Boolean huan(String id,String bookname); 16 | 17 | /** 18 | * 判断该用户是否已经借过此书 19 | * @param id 20 | * @param bookname 21 | * @return 22 | */ 23 | public boolean isBorrow(String id,String bookname); 24 | 25 | /** 26 | * 添加借书信息 27 | * @param info 28 | * @return 29 | */ 30 | public boolean add(Info info); 31 | 32 | /** 33 | * 查询此书是否借出 34 | * @param bookname 35 | * @return 36 | */ 37 | public boolean select(String bookname); 38 | 39 | public List searchBorrow(); 40 | } 41 | -------------------------------------------------------------------------------- /dao/IManagerDao.java: -------------------------------------------------------------------------------- 1 | package com.henu.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.henu.bean.Book; 6 | import com.henu.bean.Manager; 7 | import com.henu.bean.Student; 8 | 9 | public interface IManagerDao { 10 | 11 | 12 | /** 13 | * 根据用户名得到密码 14 | * @param username 15 | * @return 16 | */ 17 | public String getPassword(String username); 18 | 19 | /** 20 | * 改变管理员的激活状态 21 | * @param username 22 | * @return 23 | */ 24 | public boolean setState(String username); 25 | 26 | /** 27 | * 查看管理员的激活状态 28 | * @param username 29 | * @return 30 | */ 31 | public boolean checkState(String username); 32 | 33 | /** 34 | * 通过激活码查找用户名 35 | * @param code 36 | */ 37 | public String findUserByCode(String code); 38 | 39 | /** 40 | * 添加管理员 41 | * @param manager 42 | */ 43 | public void addAdmin(Manager manager); 44 | 45 | /** 46 | * 管理员登录 47 | * @param username 48 | * @param pwd 49 | * @return 50 | */ 51 | public boolean login(String username,String pwd); 52 | 53 | 54 | /** 55 | * 登录成功后修改标志位1 56 | * @param id 57 | */ 58 | public void change(String username); 59 | 60 | /** 61 | * 管理员退出,修改islogin的值为0 62 | * @param username 63 | */ 64 | public void logout(String username); 65 | 66 | /** 67 | * 判断管理员是否登录 68 | * @param username 69 | * @return 70 | */ 71 | public boolean judgeLogin(String username); 72 | 73 | /** 74 | * 显示所有借书学生的信息 75 | * @return 76 | */ 77 | public List findBorrowBook(); 78 | 79 | /** 80 | * 修改管理员密码吗 81 | * @param username 用户名 82 | * @param oldPwd 旧密码 83 | * @param newPwd 新密码 84 | * @return 85 | */ 86 | public int changePwd(String username,String newPwd); 87 | 88 | /** 89 | * 更改图书的位置(更换书架) 90 | * @param bookname 书名 91 | * @param bookshelf 书架 92 | * @return 93 | */ 94 | public int changePosition(String bookname,String bookshelf); 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /dao/IStudentDao.java: -------------------------------------------------------------------------------- 1 | package com.henu.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.henu.bean.Book; 6 | import com.henu.bean.Info; 7 | import com.henu.bean.Student; 8 | 9 | public interface IStudentDao { 10 | 11 | /** 12 | * 查询总记录的条数 13 | * @return 14 | */ 15 | public int allCount(); 16 | 17 | /** 18 | * 显示所有学生信息 19 | * @return 20 | */ 21 | public List findAllStudent(); 22 | 23 | /** 24 | * 删除学生 25 | * @param id 根据学号删除学生 26 | * @return 受影响的记录的条数 27 | */ 28 | public int deleteStudent(String id); 29 | 30 | /** 31 | * 保存学生 32 | * @param student 保存的对象 33 | * @return 受影响的记录的条数 34 | */ 35 | public int addStudent(Student student); 36 | 37 | /** 38 | * 学生退出,把相应的属性设为0 39 | * @param id 40 | */ 41 | public void logout(String id); 42 | 43 | /** 44 | * 判断该学生是否登录 45 | * @param id 46 | * @return 47 | */ 48 | public boolean judgeLogin(String id); 49 | 50 | /** 51 | * 学生登录 52 | * @param id 学号 53 | * @param name 姓名 54 | * @return 登录成功返回true,否则返回false 55 | */ 56 | public boolean login(String id,String name); 57 | 58 | 59 | /** 60 | * 登录成功后修改标志位1 61 | * @param id 62 | */ 63 | public void change(String id); 64 | 65 | /** 66 | * 查询借书信息 67 | * @param id 学号 68 | * @return 借书信息 69 | */ 70 | public List findById(String id); 71 | 72 | /** 73 | * 借书 74 | * @param book 图书对象 75 | * @return 受影响个数 76 | */ 77 | public int add(Book book); 78 | 79 | /** 80 | * 还书 81 | * @param book 82 | * @return 83 | */ 84 | public int delete(String bookname); 85 | } 86 | -------------------------------------------------------------------------------- /factory/DaoFactory.java: -------------------------------------------------------------------------------- 1 | package com.henu.factory; 2 | 3 | import com.henu.dao.IBookDao; 4 | import com.henu.dao.IInfoDao; 5 | import com.henu.dao.IManagerDao; 6 | import com.henu.dao.IStudentDao; 7 | import com.henu.impl.BookDaoImpl; 8 | import com.henu.impl.InfoDaoImpl; 9 | import com.henu.impl.ManagerDaoImpl; 10 | import com.henu.impl.StudentDaoImpl; 11 | 12 | public class DaoFactory { 13 | public static IStudentDao getStudentDaoImpl(){ 14 | return new StudentDaoImpl(); 15 | } 16 | 17 | public static IManagerDao getManagerDaoImpl(){ 18 | return new ManagerDaoImpl(); 19 | } 20 | 21 | public static IBookDao getBookDaoImpl(){ 22 | return new BookDaoImpl(); 23 | } 24 | 25 | public static IInfoDao getInfoDaoImpl(){ 26 | return new InfoDaoImpl(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /impl/BookDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.henu.impl; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.henu.Db.DbUtil; 10 | import com.henu.bean.Book; 11 | import com.henu.dao.IBookDao; 12 | import com.sun.xml.internal.ws.db.glassfish.BridgeWrapper; 13 | 14 | public class BookDaoImpl implements IBookDao { 15 | 16 | @Override 17 | public int addBook(Book book) { 18 | int result = 0; 19 | String sql = "insert into book(bookname,author,press,pubdate,type,bookshelf,count) values (?,?,?,?,?,?,?)"; 20 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 21 | try { 22 | ps.setString(1, book.getBookname()); 23 | ps.setString(2, book.getAuthor()); 24 | ps.setString(3, book.getPress()); 25 | ps.setString(4, book.getPubdate()); 26 | ps.setString(5, book.getType()); 27 | ps.setString(6, book.getBookshelf()); 28 | ps.setInt(7, book.getCount()); 29 | result = ps.executeUpdate(); 30 | } catch (SQLException e) { 31 | e.printStackTrace(); 32 | } 33 | return result; 34 | } 35 | 36 | @Override 37 | public List selectAllBook() { 38 | List list = new ArrayList<>(); 39 | String sql = "select * from book"; 40 | ResultSet rs = null; 41 | rs = DbUtil.executeQuery(sql); 42 | try { 43 | while (rs.next()) { 44 | Book book = new Book(); 45 | book.setBookname(rs.getString(1)); 46 | book.setAuthor(rs.getString(2)); 47 | book.setPress(rs.getString(3)); 48 | book.setPubdate(rs.getString(4)); 49 | book.setType(rs.getString(5)); 50 | book.setBookshelf(rs.getString(6)); 51 | book.setCount(rs.getInt(7)); 52 | list.add(book); 53 | } 54 | } catch (SQLException e) { 55 | e.printStackTrace(); 56 | } 57 | return list; 58 | } 59 | 60 | @Override 61 | public int deleteBook(String bookname) { 62 | int result = 0; 63 | String sql = "delete from book where bookname=?"; 64 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 65 | try { 66 | ps.setString(1, bookname); 67 | result = ps.executeUpdate(); 68 | } catch (SQLException e) { 69 | e.printStackTrace(); 70 | } 71 | return result; 72 | } 73 | 74 | @Override 75 | public boolean isEnough(String bookname, int count) { 76 | String sql = "select count from book where bookname=?"; 77 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 78 | ResultSet rs = null; 79 | int c = 0; 80 | try { 81 | ps.setString(1, bookname); 82 | rs = ps.executeQuery(); 83 | if (rs.next()) { 84 | c = rs.getInt("count"); 85 | } 86 | } catch (SQLException e) { 87 | e.printStackTrace(); 88 | } 89 | 90 | if (c >= count) { 91 | return true; 92 | } else{ 93 | return false; 94 | } 95 | } 96 | 97 | @Override 98 | public int changeCount(String bookname, int c, String type) { 99 | int result = 0; 100 | String sql = ""; 101 | if(type.equals("jie")){ 102 | sql = "update book set count=count-? where bookname=?"; 103 | } 104 | if(type.equals("huan")){ 105 | sql = "update book set count=count+? where bookname=?"; 106 | } 107 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 108 | try { 109 | ps.setInt(1, c); 110 | ps.setString(2, bookname); 111 | result = ps.executeUpdate(); 112 | } catch (SQLException e) { 113 | e.printStackTrace(); 114 | } 115 | 116 | return result; 117 | } 118 | 119 | @Override 120 | public Book book(String bookname) { 121 | String sql = "select * from book where bookname=?"; 122 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 123 | ResultSet rs = null; 124 | Book book = new Book(); 125 | try { 126 | ps.setString(1, bookname); 127 | rs = ps.executeQuery(); 128 | if(rs.next()){ 129 | book.setBookname(rs.getString(1)); 130 | book.setAuthor(rs.getString(2)); 131 | book.setPress(rs.getString(3)); 132 | book.setPubdate(rs.getString(4)); 133 | book.setType(rs.getString(5)); 134 | book.setBookshelf(rs.getString(6)); 135 | book.setCount(rs.getInt(7)); 136 | } 137 | } catch (SQLException e) { 138 | e.printStackTrace(); 139 | } 140 | return book; 141 | } 142 | 143 | 144 | 145 | } 146 | -------------------------------------------------------------------------------- /impl/InfoDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.henu.impl; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.mail.Flags.Flag; 10 | 11 | import com.henu.Db.DbUtil; 12 | import com.henu.bean.Info; 13 | import com.henu.dao.IInfoDao; 14 | 15 | public class InfoDaoImpl implements IInfoDao { 16 | 17 | @Override 18 | public boolean add(Info info) { 19 | int result = 0; 20 | String sql = "insert into borrow(id,bookname,type,date,days,count) values(?,?,?,?,?,?)"; 21 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 22 | try { 23 | ps.setString(1, info.getId()); 24 | ps.setString(2, info.getBookname()); 25 | ps.setString(3, info.getType()); 26 | ps.setString(4, info.getDate()); 27 | ps.setInt(5, info.getDays()); 28 | ps.setInt(6, info.getCon()); 29 | result = ps.executeUpdate(); 30 | } catch (SQLException e) { 31 | e.printStackTrace(); 32 | } 33 | if (result > 0) 34 | return true; 35 | else 36 | return false; 37 | } 38 | 39 | @Override 40 | public boolean select(String bookname) { 41 | int c = 0; 42 | String sql = "select * from borrow where bookname=?"; 43 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 44 | ResultSet rs = null; 45 | try { 46 | ps.setString(1, bookname); 47 | rs = ps.executeQuery(); 48 | if(rs.next()){ 49 | c = rs.getRow(); 50 | } 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | System.out.println(bookname+" "+c); 55 | if(c > 0) 56 | return true; 57 | else 58 | return false; 59 | 60 | } 61 | 62 | @Override 63 | public List searchBorrow() 64 | { 65 | List list=new ArrayList(); 66 | String sql = "select * from borrow "; 67 | try { 68 | ResultSet rs=DbUtil.executeQuery(sql); 69 | while(rs.next()) 70 | { 71 | Info info=new Info(); 72 | info.setId(rs.getString("id")); 73 | info.setBookname(rs.getString("bookname")); 74 | info.setType(rs.getString("type")); 75 | info.setDays(rs.getInt("days")); 76 | info.setCon(rs.getInt("count")); 77 | info.setDate(rs.getString("date")); 78 | 79 | list.add(info); 80 | } 81 | } catch (Exception e) { 82 | e.printStackTrace(); 83 | } 84 | return list; 85 | } 86 | 87 | @Override 88 | public boolean isBorrow(String id, String bookname) { 89 | String sql = "select * from borrow where id=? and bookname=?"; 90 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 91 | ResultSet rs = null; 92 | boolean result = false; 93 | 94 | try { 95 | ps.setString(1, id); 96 | ps.setString(2, bookname); 97 | rs = ps.executeQuery(); 98 | if(rs.next()){ 99 | result = true; 100 | }else{ 101 | result = false; 102 | } 103 | } catch (SQLException e) { 104 | result = false; 105 | } 106 | 107 | return result; 108 | 109 | } 110 | 111 | @Override 112 | public Boolean huan(String id, String bookname) { 113 | String sql = "delete from borrow where id=? and bookname=?"; 114 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 115 | int result = 0; 116 | try { 117 | ps.setString(1, id); 118 | ps.setString(2, bookname); 119 | result = ps.executeUpdate(); 120 | } catch (SQLException e) { 121 | e.printStackTrace(); 122 | } 123 | 124 | if(result > 0){ 125 | return true; 126 | }else{ 127 | return false; 128 | } 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /impl/ManagerDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.henu.impl; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.henu.Db.DbUtil; 10 | import com.henu.bean.Book; 11 | import com.henu.bean.Manager; 12 | import com.henu.bean.Student; 13 | import com.henu.dao.IManagerDao; 14 | import com.henu.tool.DesUtils; 15 | 16 | public class ManagerDaoImpl implements IManagerDao{ 17 | 18 | @Override 19 | public List findBorrowBook() { 20 | 21 | return null; 22 | } 23 | 24 | @Override 25 | public int changePwd(String username, String newPwd) { 26 | int result = 0; 27 | String sql = "update manager set password=? where username=?"; 28 | String pwd = DesUtils.jiami(newPwd); 29 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 30 | try { 31 | ps.setString(1, pwd); 32 | ps.setString(2, username); 33 | result = ps.executeUpdate(); 34 | } catch (SQLException e) { 35 | e.printStackTrace(); 36 | } 37 | return result; 38 | } 39 | 40 | @Override 41 | public int changePosition(String bookname, String bookshelf) { 42 | int result = 0; 43 | String sql = "update book set bookshelf=? where bookname=?"; 44 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 45 | try { 46 | ps.setString(1, bookshelf); 47 | ps.setString(2, bookname); 48 | result = ps.executeUpdate(); 49 | } catch (SQLException e) { 50 | e.printStackTrace(); 51 | } 52 | return result; 53 | } 54 | 55 | @Override 56 | public void logout(String username) { 57 | String sql = "update manager set islogin=0 where username = ?"; 58 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 59 | try { 60 | ps.setString(1, username); 61 | ps.executeUpdate(); 62 | } catch (SQLException e) { 63 | e.printStackTrace(); 64 | } 65 | } 66 | 67 | @Override 68 | public boolean judgeLogin(String username) { 69 | ResultSet rs = null; 70 | int result = 0; 71 | String sql = "select islogin from manager where username = ?"; 72 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 73 | try { 74 | ps.setString(1, username); 75 | rs = ps.executeQuery(); 76 | while(rs.next()){ 77 | result = rs.getInt("islogin"); 78 | } 79 | } catch (SQLException e) { 80 | e.printStackTrace(); 81 | } 82 | if (result == 0) 83 | return true; 84 | else 85 | return false; 86 | } 87 | 88 | @Override 89 | public boolean login(String username, String pwd) { 90 | boolean flag = false; 91 | String p = DesUtils.jiami(pwd); 92 | String sql = "select password from manager where username=?"; 93 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 94 | ResultSet rs = null; 95 | try { 96 | ps.setString(1, username); 97 | rs = ps.executeQuery(); 98 | if(rs.next()){ 99 | if (rs.getString("password").equals(p)) { 100 | flag = true; 101 | } else { 102 | flag = false; 103 | } 104 | } 105 | } catch (SQLException e) { 106 | e.printStackTrace(); 107 | } 108 | return flag; 109 | } 110 | 111 | @Override 112 | public boolean checkState(String username) { 113 | boolean flag = false; 114 | String sql = "select state from manager where username=?"; 115 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 116 | ResultSet rs = null; 117 | try { 118 | ps.setString(1, username); 119 | rs = ps.executeQuery(); 120 | if(rs.next()){ 121 | if (rs.getInt("state")!=0) { 122 | flag = true; 123 | } else { 124 | flag = false; 125 | } 126 | } 127 | } catch (SQLException e) { 128 | e.printStackTrace(); 129 | } 130 | return flag; 131 | } 132 | 133 | @Override 134 | public String findUserByCode(String code) { 135 | String username=""; 136 | String sql = "select username from manager where code=?"; 137 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 138 | ResultSet rs = null; 139 | try { 140 | ps.setString(1, code); 141 | rs = ps.executeQuery(); 142 | if(rs.next()){ 143 | username = rs.getString("username"); 144 | } 145 | } catch (SQLException e) { 146 | e.printStackTrace(); 147 | } 148 | return username; 149 | } 150 | 151 | @Override 152 | public void addAdmin(Manager manager) { 153 | String sql = "insert into manager (username,password,code) values(?,?,?)"; 154 | String pwd = DesUtils.jiami(manager.getPassword()); 155 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 156 | try { 157 | ps.setString(1, manager.getUsername()); 158 | ps.setString(2, pwd); 159 | ps.setString(3, manager.getCode()); 160 | ps.executeUpdate(); 161 | } catch (SQLException e) { 162 | e.printStackTrace(); 163 | } 164 | } 165 | 166 | @Override 167 | public boolean setState(String username) { 168 | boolean result = false; 169 | String sql = "update manager set state=1 where username=?"; 170 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 171 | try { 172 | ps.setString(1, username); 173 | result = ps.execute(); 174 | } catch (SQLException e) { 175 | e.printStackTrace(); 176 | } 177 | return result; 178 | } 179 | 180 | @Override 181 | public void change(String username) { 182 | String sql = "update manager set islogin=1 where username=?"; 183 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 184 | try { 185 | ps.setString(1, username); 186 | ps.executeUpdate(); 187 | } catch (SQLException e) { 188 | e.printStackTrace(); 189 | } 190 | } 191 | 192 | @Override 193 | public String getPassword(String username) { 194 | String sql = "select password from manager where username=?"; 195 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 196 | String password = ""; 197 | ResultSet rs = null; 198 | try { 199 | ps.setString(1, username); 200 | rs = ps.executeQuery(); 201 | if (rs.next()) { 202 | password = DesUtils.jiemi(rs.getString(1)); 203 | } 204 | } catch (SQLException e) { 205 | e.printStackTrace(); 206 | } 207 | return password; 208 | } 209 | 210 | } 211 | -------------------------------------------------------------------------------- /impl/StudentDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.henu.impl; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.henu.Db.DbUtil; 10 | import com.henu.bean.Book; 11 | import com.henu.bean.Info; 12 | import com.henu.bean.Student; 13 | import com.henu.dao.IStudentDao; 14 | 15 | public class StudentDaoImpl implements IStudentDao { 16 | 17 | @Override 18 | public int deleteStudent(String id) { 19 | int result = 0; 20 | String sql = "delete from student where id=?"; 21 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 22 | try { 23 | ps.setString(1, id); 24 | result = ps.executeUpdate(); 25 | } catch (SQLException e) { 26 | e.printStackTrace(); 27 | } 28 | return result; 29 | } 30 | 31 | 32 | @Override 33 | public int addStudent(Student student) { 34 | int result = 0; 35 | String sql = "insert into student(id,name,gender,phone,email,department,islogin) values (?,?,?,?,?,?,?)"; 36 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 37 | try { 38 | ps.setString(1, student.getId()); 39 | ps.setString(2, student.getName()); 40 | ps.setString(3, student.getGender()); 41 | ps.setString(4, student.getPhone()); 42 | ps.setString(5, student.getEmail()); 43 | ps.setString(6, student.getDepartment()); 44 | ps.setInt(7, student.getIslogin()); 45 | result = ps.executeUpdate(); 46 | } catch (SQLException e) { 47 | e.printStackTrace(); 48 | } 49 | return result; 50 | } 51 | 52 | @Override 53 | public boolean login(String id, String name) { 54 | boolean flag = false; 55 | String sql = "select name from student where id=?"; 56 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 57 | ResultSet rs = null; 58 | try { 59 | ps.setString(1, id); 60 | rs = ps.executeQuery(); 61 | if(rs.next()){ 62 | if (rs.getString("name").equals(name)) { 63 | flag = true; 64 | } else { 65 | flag = false; 66 | } 67 | } 68 | } catch (SQLException e) { 69 | e.printStackTrace(); 70 | } 71 | return flag; 72 | } 73 | 74 | @Override 75 | public List findAllStudent() { 76 | List list = new ArrayList<>(); 77 | String sql = "select * from student"; 78 | ResultSet rs = null; 79 | rs = DbUtil.executeQuery(sql); 80 | try { 81 | while(rs.next()){ 82 | Student student = new Student(); 83 | student.setId(rs.getString(1)); 84 | student.setName(rs.getString(2)); 85 | student.setGender(rs.getString(3)); 86 | student.setPhone(rs.getString(4)); 87 | student.setEmail(rs.getString(5)); 88 | student.setDepartment(rs.getString(6)); 89 | list.add(student); 90 | } 91 | } catch (SQLException e) { 92 | e.printStackTrace(); 93 | } 94 | return list; 95 | } 96 | 97 | @Override 98 | public List findById(String id) { 99 | List list = new ArrayList<>(); 100 | ResultSet rs = null; 101 | String sql = "select * from borrow where id=?"; 102 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 103 | try { 104 | ps.setString(1, id); 105 | rs = ps.executeQuery(); 106 | while (rs.next()) { 107 | Info info = new Info(); 108 | info.setBookname(rs.getString("bookname")); 109 | info.setType(rs.getString("type")); 110 | info.setDate(rs.getString("date")); 111 | info.setDays(rs.getInt("days")); 112 | info.setCon(rs.getInt("count")); 113 | list.add(info); 114 | } 115 | } catch (SQLException e) { 116 | // TODO Auto-generated catch block 117 | e.printStackTrace(); 118 | } 119 | return list; 120 | } 121 | 122 | @Override 123 | public int add(Book book) { 124 | int result = 0; 125 | String sql = "insert into book(bookname,author,press,pubdate,type,bookshelf,count) values(?,?,?,?,?,?,?)"; 126 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 127 | try { 128 | ps.setString(1, book.getBookname()); 129 | ps.setString(2, book.getAuthor()); 130 | ps.setString(3, book.getPress()); 131 | ps.setString(4, book.getPubdate()); 132 | ps.setString(5, book.getType()); 133 | ps.setString(6, book.getBookshelf()); 134 | ps.setInt(7, book.getCount()); 135 | result = ps.executeUpdate(); 136 | } catch (SQLException e) { 137 | e.printStackTrace(); 138 | } 139 | return result; 140 | } 141 | 142 | @Override 143 | public int delete(String bookname) { 144 | int result = 0; 145 | String sql = "delete from info where bookname=?"; 146 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 147 | try { 148 | ps.setString(1, bookname); 149 | result = ps.executeUpdate(); 150 | } catch (SQLException e) { 151 | e.printStackTrace(); 152 | } 153 | return result; 154 | } 155 | 156 | @Override 157 | public void logout(String id) { 158 | String sql = "update student set islogin=0 where id = ?"; 159 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 160 | try { 161 | ps.setString(1, id); 162 | ps.executeUpdate(); 163 | } catch (SQLException e) { 164 | e.printStackTrace(); 165 | } 166 | } 167 | 168 | @Override 169 | public boolean judgeLogin(String id) { 170 | ResultSet rs = null; 171 | String sql = "select islogin from student where id = ?"; 172 | int login = 0; 173 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 174 | try { 175 | ps.setString(1, id); 176 | rs = ps.executeQuery(); 177 | while(rs.next()){ 178 | login = rs.getInt("islogin"); 179 | } 180 | } catch (SQLException e) { 181 | e.printStackTrace(); 182 | } 183 | if (login == 0) 184 | return true; 185 | else 186 | return false; 187 | } 188 | 189 | 190 | @Override 191 | public void change(String id) { 192 | String sql = "update student set islogin=1 where id=?"; 193 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 194 | try { 195 | ps.setString(1, id); 196 | ps.executeUpdate(); 197 | } catch (SQLException e) { 198 | e.printStackTrace(); 199 | } 200 | } 201 | 202 | @Override 203 | public int allCount() { 204 | int count = 0; 205 | String sql = "select count(*) from student"; 206 | ResultSet rs = null; 207 | rs = DbUtil.executeQuery(sql); 208 | try { 209 | if(rs.next()){ 210 | count = rs.getInt(1); 211 | } 212 | DbUtil.close(); 213 | } catch (SQLException e) { 214 | e.printStackTrace(); 215 | } 216 | return count; 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /library.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat Premium Data Transfer 3 | 4 | Source Server : mysql 5 | Source Server Type : MySQL 6 | Source Server Version : 50731 7 | Source Host : localhost:3306 8 | Source Schema : library 9 | 10 | Target Server Type : MySQL 11 | Target Server Version : 50731 12 | File Encoding : 65001 13 | 14 | Date: 27/12/2020 11:32:29 15 | */ 16 | 17 | SET NAMES utf8mb4; 18 | SET FOREIGN_KEY_CHECKS = 0; 19 | 20 | -- ---------------------------- 21 | -- Table structure for book 22 | -- ---------------------------- 23 | DROP TABLE IF EXISTS `book`; 24 | CREATE TABLE `book` ( 25 | `bookname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '书名', 26 | `author` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '作者', 27 | `press` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '出版社', 28 | `pubdate` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '出版日期', 29 | `type` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书类型', 30 | `bookshelf` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '书架', 31 | `count` int(11) NOT NULL COMMENT '数量', 32 | PRIMARY KEY (`bookname`) USING BTREE 33 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; 34 | 35 | -- ---------------------------- 36 | -- Records of book 37 | -- ---------------------------- 38 | INSERT INTO `book` VALUES ('国内外建筑风格大全', '托尼', '私人教育出版社', '2020-07-30', '建筑设计类', '6', 899); 39 | INSERT INTO `book` VALUES ('心理学基础', '萨顶顶', '同济大学出版社', '2020-01-30', '外语类', '3', 869); 40 | INSERT INTO `book` VALUES ('数据结构与数据库', '吴强', '山东大学出版社', '2020-12-30', '计算机科学类', '2', 29); 41 | INSERT INTO `book` VALUES ('新东方英语词汇', '俞敏洪', '人民日报出版社', '2020-08-09', '外语类', '2', 9); 42 | INSERT INTO `book` VALUES ('算法设计', '郑宗汉', '同济大学出版社', '2020-07-29', '计算机科学类', '1', 57); 43 | INSERT INTO `book` VALUES ('计算机组成原理', '王道', '电子工业出版社', '2020-08-16', '计算机科学类', '1', 6); 44 | INSERT INTO `book` VALUES ('计算机网络', '吴英', '人民日报出版社', '2020-07-29', '计算机科学类', '1', 84); 45 | 46 | -- ---------------------------- 47 | -- Table structure for borrow 48 | -- ---------------------------- 49 | DROP TABLE IF EXISTS `borrow`; 50 | CREATE TABLE `borrow` ( 51 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '学号', 52 | `bookname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '书名', 53 | `type` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '类型', 54 | `date` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '借书日期', 55 | `days` int(11) NOT NULL COMMENT '借阅天数', 56 | `count` int(11) NOT NULL COMMENT '借阅数量', 57 | PRIMARY KEY (`id`, `bookname`) USING BTREE, 58 | INDEX `bookname`(`bookname`) USING BTREE, 59 | CONSTRAINT `borrow_ibfk_1` FOREIGN KEY (`id`) REFERENCES `student` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, 60 | CONSTRAINT `borrow_ibfk_2` FOREIGN KEY (`bookname`) REFERENCES `book` (`bookname`) ON DELETE RESTRICT ON UPDATE RESTRICT 61 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; 62 | 63 | -- ---------------------------- 64 | -- Records of borrow 65 | -- ---------------------------- 66 | INSERT INTO `borrow` VALUES ('201800121048', '数据结构与数据库', '计算机科学类', '2020-12-27', 2, 1); 67 | 68 | -- ---------------------------- 69 | -- Table structure for manager 70 | -- ---------------------------- 71 | DROP TABLE IF EXISTS `manager`; 72 | CREATE TABLE `manager` ( 73 | `username` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '帐号', 74 | `password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码', 75 | `islogin` int(10) NOT NULL DEFAULT 0 COMMENT '是否登录', 76 | `code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '激活码', 77 | `state` int(1) NOT NULL DEFAULT 0 COMMENT '激活状态', 78 | PRIMARY KEY (`username`) USING BTREE 79 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; 80 | 81 | -- ---------------------------- 82 | -- Records of manager 83 | -- ---------------------------- 84 | INSERT INTO `manager` VALUES ('admin', 'ff0ad942f3afc7a5', 1, '', 1); 85 | 86 | -- ---------------------------- 87 | -- Table structure for student 88 | -- ---------------------------- 89 | DROP TABLE IF EXISTS `student`; 90 | CREATE TABLE `student` ( 91 | `id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '学号', 92 | `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '姓名', 93 | `gender` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '性别', 94 | `phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '电话', 95 | `email` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '邮箱', 96 | `department` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '院系', 97 | `islogin` int(10) NULL DEFAULT 0 COMMENT '是否登录', 98 | PRIMARY KEY (`id`) USING BTREE 99 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; 100 | 101 | -- ---------------------------- 102 | -- Records of student 103 | -- ---------------------------- 104 | INSERT INTO `student` VALUES ('201800121048', '王福超', '男', '17667501727', '1315080281@qq.com', '信息科学与工程学院', 1); 105 | INSERT INTO `student` VALUES ('201800121112', '钟玉池', '女', '123456789', '123456789@qq.com', '计算机学院', 1); 106 | INSERT INTO `student` VALUES ('2020001', '001', '男', '001', '001@gmail.com', '环境学院', 0); 107 | INSERT INTO `student` VALUES ('2020002', '002', '女', '002', '002@qq.com', '生物科学学院', 0); 108 | 109 | SET FOREIGN_KEY_CHECKS = 1; 110 | 111 | -------------------------------------------------------------------------------- /service/UserManager.java: -------------------------------------------------------------------------------- 1 | package com.henu.service; 2 | 3 | import java.util.Properties; 4 | import java.util.UUID; 5 | 6 | import javax.mail.Message; 7 | import javax.mail.Session; 8 | import javax.mail.Transport; 9 | import javax.mail.internet.InternetAddress; 10 | import javax.mail.internet.MimeMessage; 11 | 12 | import com.henu.bean.Manager; 13 | import com.henu.factory.DaoFactory; 14 | 15 | public class UserManager { 16 | public void Register(String username, String password, String email) { 17 | 18 | // 生成用户code 19 | String code = UUID.randomUUID().toString().replace("-", ""); 20 | 21 | // 添加用户 22 | Manager manager = new Manager(); 23 | manager.setUsername(username); 24 | manager.setPassword(password); 25 | manager.setCode(code); 26 | DaoFactory.getManagerDaoImpl().addAdmin(manager); 27 | 28 | // 向用户发送邮件 29 | sendMail(email, code); 30 | } 31 | 32 | public static boolean sendMail(String email, String code) { 33 | try { 34 | Properties props = new Properties(); 35 | props.put("username", "123456789@163.com"); 36 | props.put("password", "q123456789"); 37 | // 发送邮件协议名称 38 | props.put("mail.transport.protocol", "smtp"); 39 | // 设置邮件服务器主机名 40 | props.put("mail.smtp.host", "smtp.163.com"); 41 | props.put("mail.smtp.port", "25"); 42 | 43 | Session mailSession = Session.getDefaultInstance(props); 44 | 45 | // 创建邮件对象 46 | Message message = new MimeMessage(mailSession); 47 | // 发件人 48 | message.setFrom(new InternetAddress("123456789@163.com")); 49 | message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); 50 | // 主题 51 | message.setSubject("激活邮件"); 52 | // HTML内容 53 | message.setContent( 54 | "

此邮件为官方激活邮件!请点击下面链接完成激活操作!

http://localhost:8080/Library/mainLogin.jsp

", 56 | "text/html;charset=UTF-8"); 57 | message.saveChanges(); 58 | 59 | Transport transport = mailSession.getTransport("smtp"); 60 | transport.connect(props.getProperty("mail.smtp.host"), props.getProperty("username"), 61 | props.getProperty("password")); 62 | transport.sendMessage(message, message.getAllRecipients()); 63 | transport.close(); 64 | } catch (Exception e) { 65 | e.printStackTrace(); 66 | System.out.println(e); 67 | return false; 68 | } 69 | return true; 70 | } 71 | 72 | //激活用户 73 | public boolean Active(String code){ 74 | String username = DaoFactory.getManagerDaoImpl().findUserByCode(code); 75 | if(username!=null&&!username.equals("")){ 76 | //将用户的状态设为激活 77 | DaoFactory.getManagerDaoImpl().setState(username); 78 | return true; 79 | }else{ 80 | return false; 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /servlet/ActiveServlet.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.service.UserManager; 12 | 13 | /** 14 | * Servlet implementation class ActiveServlet 15 | */ 16 | @WebServlet("/ActiveServlet") 17 | public class ActiveServlet extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public ActiveServlet() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 30 | */ 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 32 | HttpSession session = request.getSession(); 33 | String code = (String)session.getAttribute("code"); 34 | UserManager userManager = new UserManager(); 35 | if(userManager.Active(code)){ 36 | //激活成功后,跳转到登录界面 37 | request.setAttribute("message", "激活成功!"); 38 | request.getRequestDispatcher("mainLogin.jsp").forward(request, response); 39 | } 40 | } 41 | 42 | /** 43 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 44 | */ 45 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 46 | // TODO Auto-generated method stub 47 | doGet(request, response); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /servlet/AddBook.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.bean.Book; 12 | import com.henu.factory.DaoFactory; 13 | 14 | /** 15 | * Servlet implementation class AddBook 16 | */ 17 | @WebServlet("/AddBook") 18 | public class AddBook extends HttpServlet { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * @see HttpServlet#HttpServlet() 23 | */ 24 | public AddBook() { 25 | super(); 26 | // TODO Auto-generated constructor stub 27 | } 28 | 29 | /** 30 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 31 | */ 32 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 33 | String bookname = request.getParameter("bookname"); 34 | String author = request.getParameter("author"); 35 | String press = request.getParameter("press"); 36 | String date = request.getParameter("date"); 37 | String type = request.getParameter("type"); 38 | String bookshelf = request.getParameter("bookshelf"); 39 | int count = Integer.parseInt(request.getParameter("count")); 40 | Book book = new Book(bookname,author,press,date,type,bookshelf,count); 41 | int result = DaoFactory.getBookDaoImpl().addBook(book); 42 | HttpSession session = request.getSession(); 43 | if(result > 0){ 44 | session.setAttribute("success", ""); 45 | }else{ 46 | session.setAttribute("success", ""); 47 | } 48 | response.sendRedirect("admin/admin_addBook.jsp"); 49 | } 50 | 51 | /** 52 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 53 | */ 54 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 55 | // TODO Auto-generated method stub 56 | doGet(request, response); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /servlet/AddOneStudent.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.bean.Student; 12 | import com.henu.factory.DaoFactory; 13 | 14 | /** 15 | * Servlet implementation class AddOneStudent 16 | */ 17 | @WebServlet("/AddOneStudent") 18 | public class AddOneStudent extends HttpServlet { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * @see HttpServlet#HttpServlet() 23 | */ 24 | public AddOneStudent() { 25 | super(); 26 | // TODO Auto-generated constructor stub 27 | } 28 | 29 | /** 30 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 31 | */ 32 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 33 | String id = request.getParameter("sno"); 34 | String name = request.getParameter("xingming"); 35 | String gender = request.getParameter("gender"); 36 | String phone = request.getParameter("phone"); 37 | String email = request.getParameter("email"); 38 | String department = request.getParameter("yuan"); 39 | Student student = new Student(id, name, gender, phone, email, department, 0); 40 | int result = DaoFactory.getStudentDaoImpl().addStudent(student); 41 | HttpSession session = request.getSession(); 42 | if(result > 0){ 43 | session.setAttribute("success", ""); 44 | }else{ 45 | session.setAttribute("error", ""); 46 | } 47 | request.getRequestDispatcher("FenYe").forward(request, response); 48 | } 49 | 50 | /** 51 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 52 | */ 53 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 54 | // TODO Auto-generated method stub 55 | doGet(request, response); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /servlet/BorrowBook.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.bean.Book; 12 | import com.henu.bean.Info; 13 | import com.henu.factory.DaoFactory; 14 | 15 | /** 16 | * Servlet implementation class BorrowBook 17 | */ 18 | @WebServlet("/BorrowBook") 19 | public class BorrowBook extends HttpServlet { 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * @see HttpServlet#HttpServlet() 24 | */ 25 | public BorrowBook() { 26 | super(); 27 | // TODO Auto-generated constructor stub 28 | } 29 | 30 | /** 31 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 32 | */ 33 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 34 | HttpSession session = request.getSession(); 35 | String id = (String)session.getAttribute("studentId"); 36 | String bookname = request.getParameter("bookname"); 37 | int count = Integer.parseInt(request.getParameter("counts")); 38 | int day = Integer.parseInt(request.getParameter("days")); 39 | String date = request.getParameter("date"); 40 | Book book = DaoFactory.getBookDaoImpl().book(bookname); 41 | Info info = new Info(id,bookname,book.getType(),date,day,count); 42 | 43 | if(DaoFactory.getInfoDaoImpl().isBorrow(id, bookname)){ 44 | session.setAttribute("error", ""); 45 | response.sendRedirect("student/student_lend.jsp"); 46 | }else{ 47 | if(DaoFactory.getBookDaoImpl().isEnough(bookname, count)){ 48 | if(DaoFactory.getInfoDaoImpl().add(info)){ 49 | //相应书籍数量减少 50 | DaoFactory.getBookDaoImpl().changeCount(bookname, count, "jie"); 51 | session.setAttribute("success", ""); 52 | request.getRequestDispatcher("ShowBookInfo").forward(request, response); 53 | } 54 | }else{ 55 | session.setAttribute("error", ""); 56 | response.sendRedirect("student/student_lend.jsp"); 57 | } 58 | } 59 | } 60 | 61 | /** 62 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 63 | */ 64 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 65 | // TODO Auto-generated method stub 66 | doGet(request, response); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /servlet/ChangeAdminPwd.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.factory.DaoFactory; 12 | 13 | /** 14 | * Servlet implementation class ChangeAdminPwd 15 | */ 16 | @WebServlet("/ChangeAdminPwd") 17 | public class ChangeAdminPwd extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public ChangeAdminPwd() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 30 | * response) 31 | */ 32 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 33 | throws ServletException, IOException { 34 | HttpSession session = request.getSession(); 35 | String username = (String) session.getAttribute("masterId"); 36 | String old = request.getParameter("oldpwd"); 37 | String newPwd = request.getParameter("newPwd1"); 38 | String newPwd2 = request.getParameter("newPwd2"); 39 | String oldpwd = DaoFactory.getManagerDaoImpl().getPassword(username); 40 | int i = 0; 41 | if (!old.equals(oldpwd)) { 42 | session.setAttribute("error", ""); 43 | } else { 44 | if (!newPwd.equals(newPwd2)) { 45 | session.setAttribute("error", ""); 46 | } else { 47 | i = DaoFactory.getManagerDaoImpl().changePwd(username, newPwd); 48 | } 49 | } 50 | 51 | if (i > 0) { 52 | session.setAttribute("success", ""); 53 | } 54 | 55 | response.sendRedirect("admin/admin_changePwd.jsp"); 56 | } 57 | 58 | /** 59 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 60 | * response) 61 | */ 62 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 63 | throws ServletException, IOException { 64 | // TODO Auto-generated method stub 65 | doGet(request, response); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /servlet/DeleteBook.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.factory.DaoFactory; 12 | 13 | /** 14 | * Servlet implementation class DeleteBook 15 | */ 16 | @WebServlet("/DeleteBook") 17 | public class DeleteBook extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public DeleteBook() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 30 | */ 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 32 | String bookname = request.getParameter("name"); 33 | HttpSession session = request.getSession(); 34 | if(DaoFactory.getInfoDaoImpl().select(bookname)){ 35 | session.setAttribute("error", ""); 36 | }else{ 37 | DaoFactory.getBookDaoImpl().deleteBook(bookname); 38 | } 39 | 40 | request.getRequestDispatcher("SelectAllBook").forward(request, response); 41 | } 42 | 43 | /** 44 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 45 | */ 46 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 47 | // TODO Auto-generated method stub 48 | doGet(request, response); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /servlet/Exit.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.factory.DaoFactory; 12 | 13 | /** 14 | * Servlet implementation class Exit 15 | */ 16 | @WebServlet("/Exit") 17 | public class Exit extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public Exit() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 30 | */ 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 32 | String type = request.getParameter("type"); 33 | HttpSession session = request.getSession(); 34 | if(type.equals("student")){ 35 | String id = (String)session.getAttribute("studentId"); 36 | DaoFactory.getStudentDaoImpl().logout(id); 37 | response.sendRedirect("mainLogin.jsp"); 38 | } 39 | if(type.equals("admin")){ 40 | String username = (String)session.getAttribute("masterId"); 41 | DaoFactory.getManagerDaoImpl().logout(username); 42 | response.sendRedirect("mainLogin.jsp"); 43 | } 44 | } 45 | 46 | /** 47 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 48 | */ 49 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 50 | // TODO Auto-generated method stub 51 | doGet(request, response); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /servlet/ExportBookInfo.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.sql.ResultSet; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.henu.Db.DbUtil; 14 | 15 | import jxl.Workbook; 16 | import jxl.write.Label; 17 | 18 | /** 19 | * Servlet implementation class ExportBookInfo 20 | */ 21 | @WebServlet("/ExportBookInfo") 22 | public class ExportBookInfo extends HttpServlet { 23 | private static final long serialVersionUID = 1L; 24 | 25 | /** 26 | * @see HttpServlet#HttpServlet() 27 | */ 28 | public ExportBookInfo() { 29 | super(); 30 | // TODO Auto-generated constructor stub 31 | } 32 | 33 | /** 34 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 35 | */ 36 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 37 | try { 38 | //得到图书数据库中全部数据 39 | String sql = "select * from book"; 40 | ResultSet rs = null; 41 | rs = DbUtil.executeQuery(sql); 42 | 43 | //新建Excel文件 44 | //String filePath = request.getRealPath("Test.xls"); 45 | String filePath = "E:/Book.xls"; 46 | File myFilePath = new File(filePath); 47 | 48 | //检查文件是否存在,若存在则删除 49 | if(myFilePath.exists()) 50 | myFilePath.delete(); 51 | 52 | //创建一个新的.xls文件 53 | myFilePath.createNewFile(); 54 | 55 | //整理数据流 56 | //OutputStream outf = new FileOutputStream(filePath); 57 | jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(myFilePath); 58 | 59 | //生成名为“sheettest”的工作表,参数0表示这是第一页 60 | jxl.write.WritableSheet ws = wwb.createSheet("sheettest", 0); 61 | 62 | int i=0,j=0; 63 | //getMetaData()获取此ResultSet对象列的编号、类型、属性 64 | //getColumnCount()返回此ResultSet对象中的列数 65 | ws.addCell(new Label(0,0,"书名")); 66 | ws.addCell(new Label(1,0,"作者")); 67 | ws.addCell(new Label(2,0,"出版社")); 68 | ws.addCell(new Label(3,0,"出版日期")); 69 | ws.addCell(new Label(4,0,"类型")); 70 | ws.addCell(new Label(5,0,"书架")); 71 | ws.addCell(new Label(6,0,"数量")); 72 | 73 | 74 | //列数:rs.getMetaData().getColumnCount()); 75 | //插入数据库中的数据 76 | while(rs.next()){ 77 | for(int k=0;k 0 && t < pages) 57 | currpage = t; // 将点击的页码号赋给当前页码 58 | if(t==0) 59 | currpage = 1; 60 | if(t==pages) 61 | currpage = pages; 62 | } 63 | 64 | List list = DaoFactory.getStudentDaoImpl().findAllStudent();// 查出学生信息 65 | 66 | 67 | 68 | StringBuilder sb1 = new StringBuilder(); // 存放本页图书信息 69 | // 取出本页的数据 70 | for (int i = (currpage - 1) * pageSize; i < list.size() && i < currpage * pageSize; i++) { 71 | Student student = list.get(i); 72 | sb1.append(""+student.getId()+""); 73 | sb1.append(""+student.getName()+""); 74 | sb1.append(""+student.getGender()+""); 75 | sb1.append(""+student.getPhone()+""); 76 | sb1.append(""+student.getEmail()+""); 77 | sb1.append(""+student.getDepartment()+""); 78 | sb1.append("查询借阅信息"); 79 | } 80 | 81 | session.setAttribute("sb1", sb1.toString()); 82 | 83 | StringBuilder sb = new StringBuilder(); // 存放页数信息 84 | 85 | for (int i = 1; i <= pages; i++) { 86 | // 构建分页当行条 87 | if (i == currpage) { 88 | sb.append("
  • " + i + "
  • "); 89 | } else { 90 | sb.append("
  • " + i + "
  • "); 91 | } 92 | } 93 | 94 | if(currpage == 1){ 95 | session.setAttribute("current1", 0); 96 | }else{ 97 | session.setAttribute("current1", currpage-1); 98 | } 99 | 100 | if(currpage == pages){ 101 | session.setAttribute("current2", pages); 102 | }else{ 103 | session.setAttribute("current2", currpage+1); 104 | } 105 | 106 | session.setAttribute("bar", sb.toString()); 107 | // 跳转到显示界面 108 | response.sendRedirect("admin/admin_selectAll.jsp"); 109 | //request.getRequestDispatcher("admin/admin_selectAll.jsp").forward(request, response); 110 | 111 | } 112 | 113 | /** 114 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 115 | * response) 116 | */ 117 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 118 | throws ServletException, IOException { 119 | // TODO Auto-generated method stub 120 | doGet(request, response); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /servlet/HuanShu.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.factory.DaoFactory; 12 | 13 | /** 14 | * Servlet implementation class HuanShu 15 | */ 16 | @WebServlet("/HuanShu") 17 | public class HuanShu extends HttpServlet { 18 | private static final long serialVersionUID = 1L; 19 | 20 | /** 21 | * @see HttpServlet#HttpServlet() 22 | */ 23 | public HuanShu() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 30 | */ 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 32 | HttpSession session = request.getSession(); 33 | String bookname = request.getParameter("book"); 34 | String id = (String)session.getAttribute("studentId"); 35 | int con = Integer.parseInt(request.getParameter("count")); 36 | DaoFactory.getBookDaoImpl().changeCount(bookname, con, "huan"); 37 | if(DaoFactory.getInfoDaoImpl().huan(id, bookname)){ 38 | session.setAttribute("success", ""); 39 | }else{ 40 | session.setAttribute("error", ""); 41 | } 42 | request.getRequestDispatcher("ShowBookInfo").forward(request, response); 43 | } 44 | 45 | /** 46 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 47 | */ 48 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 49 | // TODO Auto-generated method stub 50 | doGet(request, response); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /servlet/ImportStudentFromExcel.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import java.sql.PreparedStatement; 5 | import java.util.List; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | 14 | import com.henu.Db.DbUtil; 15 | import com.henu.bean.Student; 16 | import com.henu.factory.DaoFactory; 17 | import com.henu.tool.GetStudentData; 18 | 19 | /** 20 | * Servlet implementation class ImportFromExcel 21 | */ 22 | @WebServlet("/ImportFromExcel") 23 | public class ImportStudentFromExcel extends HttpServlet { 24 | private static final long serialVersionUID = 1L; 25 | 26 | /** 27 | * @see HttpServlet#HttpServlet() 28 | */ 29 | public ImportStudentFromExcel() { 30 | super(); 31 | // TODO Auto-generated constructor stub 32 | } 33 | 34 | /** 35 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 36 | */ 37 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 38 | doPost(request, response); 39 | } 40 | 41 | /** 42 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 43 | */ 44 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 45 | //选择的路径,前段需要更改 46 | String path = request.getParameter("file"); 47 | List list = GetStudentData.getAllByExcel(path); 48 | HttpSession session = request.getSession(); 49 | try { 50 | for(Student student : list){ 51 | if(!GetStudentData.isExist(student.getId())){ 52 | //如果数据库中没有此记录,则添加进去 53 | DaoFactory.getStudentDaoImpl().addStudent(student); 54 | } 55 | } 56 | session.setAttribute("success", ""); 57 | DbUtil.close(); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | //添加完后要跳转的界面 62 | request.getRequestDispatcher("FenYe").forward(request, response); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /servlet/LoginCheck.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | 13 | import com.henu.factory.DaoFactory; 14 | 15 | /** 16 | * Servlet implementation class LoginCheck 17 | */ 18 | @WebServlet("/LoginCheck") 19 | public class LoginCheck extends HttpServlet { 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * @see HttpServlet#HttpServlet() 24 | */ 25 | public LoginCheck() { 26 | super(); 27 | // TODO Auto-generated constructor stub 28 | } 29 | 30 | /** 31 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 32 | * response) 33 | */ 34 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 35 | throws ServletException, IOException { 36 | request.setCharacterEncoding("utf-8"); 37 | String type = request.getParameter("name"); 38 | String username,pwd; 39 | PrintWriter out = response.getWriter(); 40 | HttpSession session = request.getSession(); 41 | //普通用户登录 42 | if (type.equals("user")) { 43 | //得到输入的用户名,判断该用户是否已经登录 44 | username = request.getParameter("userid"); 45 | session.setAttribute("studentId", username); 46 | pwd = request.getParameter("userpwd"); 47 | if(DaoFactory.getStudentDaoImpl().judgeLogin(username)){ 48 | //密码正确,进入学生首页 49 | if(DaoFactory.getStudentDaoImpl().login(username, pwd)){ 50 | DaoFactory.getStudentDaoImpl().change(username); 51 | response.sendRedirect("student/student_about.jsp"); 52 | }else{ 53 | //密码错误,返回登录页面 54 | session.setAttribute("error", ""); 55 | response.sendRedirect("mainLogin.jsp"); 56 | } 57 | }else{ 58 | //若用户已登录,返回登录界面 59 | session.setAttribute("error", ""); 60 | response.sendRedirect("student/student_about.jsp"); 61 | } 62 | } 63 | 64 | //管理员登录 65 | if (type.equals("manager")) { 66 | username = request.getParameter("masterid"); 67 | session.setAttribute("masterId", username); 68 | pwd = request.getParameter("masterpwd"); 69 | //判断该账户是否已经激活 70 | if(DaoFactory.getManagerDaoImpl().checkState(username)){ 71 | if(DaoFactory.getManagerDaoImpl().judgeLogin(username)){ 72 | //密码正确进入管理员界面 73 | if(DaoFactory.getManagerDaoImpl().login(username, pwd)){ 74 | DaoFactory.getManagerDaoImpl().change(username); 75 | response.sendRedirect("admin/admin_about.jsp"); 76 | }else { 77 | //密码错误,返回登录页面 78 | session.setAttribute("error", ""); 79 | response.sendRedirect("mainLogin.jsp"); 80 | } 81 | }else{ 82 | //若用户已登录,返回登录界面 83 | session.setAttribute("error", ""); 84 | response.sendRedirect("admin/admin_about.jsp"); 85 | } 86 | }else{ 87 | session.setAttribute("error", ""); 88 | response.sendRedirect("mainLogin.jsp"); 89 | } 90 | } 91 | 92 | } 93 | 94 | /** 95 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 96 | * response) 97 | */ 98 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 99 | throws ServletException, IOException { 100 | // TODO Auto-generated method stub 101 | doGet(request, response); 102 | } 103 | 104 | 105 | 106 | } 107 | -------------------------------------------------------------------------------- /servlet/RegisterAdmin.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.henu.service.UserManager; 12 | import com.henu.tool.SendMail; 13 | 14 | /** 15 | * Servlet implementation class RegisterAdmin 16 | */ 17 | @WebServlet("/RegisterAdmin") 18 | public class RegisterAdmin extends HttpServlet { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * @see HttpServlet#HttpServlet() 23 | */ 24 | public RegisterAdmin() { 25 | super(); 26 | // TODO Auto-generated constructor stub 27 | } 28 | 29 | /** 30 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 31 | */ 32 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 33 | String username = request.getParameter("username"); 34 | String password = request.getParameter("password"); 35 | String email = request.getParameter("email"); 36 | 37 | UserManager userManager = new UserManager(); 38 | 39 | SendMail sendMail = new SendMail(username, password, email, userManager); 40 | Thread thread = new Thread(sendMail); 41 | thread.start(); 42 | 43 | HttpSession session = request.getSession(); 44 | session.setAttribute("success", ""); 45 | 46 | response.sendRedirect("admin/admin_register.jsp"); 47 | } 48 | 49 | /** 50 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 51 | */ 52 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 53 | // TODO Auto-generated method stub 54 | doGet(request, response); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /servlet/SelectAllBook.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | 13 | import com.henu.bean.Book; 14 | import com.henu.factory.DaoFactory; 15 | 16 | /** 17 | * Servlet implementation class SelectAllBook 18 | */ 19 | @WebServlet("/SelectAllBook") 20 | public class SelectAllBook extends HttpServlet { 21 | private static final long serialVersionUID = 1L; 22 | 23 | /** 24 | * @see HttpServlet#HttpServlet() 25 | */ 26 | public SelectAllBook() { 27 | super(); 28 | // TODO Auto-generated constructor stub 29 | } 30 | 31 | /** 32 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 33 | * response) 34 | */ 35 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 36 | throws ServletException, IOException { 37 | List list = DaoFactory.getBookDaoImpl().selectAllBook(); 38 | String type = request.getParameter("type"); 39 | StringBuilder sb = new StringBuilder(); 40 | for (Book book : list) { 41 | sb.append("" + book.getBookname() + ""); 42 | sb.append("" + book.getAuthor() + ""); 43 | sb.append("" + book.getPress() + ""); 44 | sb.append("" + book.getPubdate() + ""); 45 | sb.append("" + book.getType() + ""); 46 | sb.append("" + book.getBookshelf() + ""); 47 | sb.append("" + book.getCount() + ""); 48 | if (type.equals("admin")) 49 | sb.append("删除"); 51 | if (type.equals("student")) 52 | sb.append("借阅"); 54 | } 55 | 56 | HttpSession session = request.getSession(); 57 | session.setAttribute("bookinfo", sb.toString()); 58 | if (type.equals("admin")) 59 | response.sendRedirect("admin/admin_changeBook.jsp"); 60 | if (type.equals("student")) 61 | response.sendRedirect("student/student_lend.jsp"); 62 | } 63 | 64 | /** 65 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse 66 | * response) 67 | */ 68 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 69 | throws ServletException, IOException { 70 | // TODO Auto-generated method stub 71 | doGet(request, response); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /servlet/SelectBorrowinfo.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | 13 | import com.henu.bean.Info; 14 | import com.henu.bean.Student; 15 | import com.henu.factory.DaoFactory; 16 | 17 | /** 18 | * Servlet implementation class SelectBorrowinfo 19 | */ 20 | @WebServlet("/SelectBorrowinfo") 21 | public class SelectBorrowinfo extends HttpServlet { 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** 25 | * @see HttpServlet#HttpServlet() 26 | */ 27 | public SelectBorrowinfo() { 28 | super(); 29 | // TODO Auto-generated constructor stub 30 | } 31 | 32 | /** 33 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 34 | */ 35 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 36 | // TODO Auto-generated method stub 37 | String studentid = request.getParameter("id"); 38 | List list=DaoFactory.getInfoDaoImpl().searchBorrow(); 39 | StringBuilder sb=new StringBuilder(); 40 | boolean isborrow=false; 41 | for(Info info:list) 42 | { 43 | if(info.getId().equals(studentid)) 44 | { 45 | System.out.println(info.getId()+" "+studentid); 46 | sb.append(""+info.getBookname()+""); 47 | sb.append(""+info.getType()+""); 48 | sb.append(""+info.getDate()+""); 49 | sb.append(""+info.getDays()+""); 50 | sb.append(""+info.getCon()+""); 51 | isborrow=true; 52 | } 53 | 54 | } 55 | HttpSession session = request.getSession(); 56 | session.setAttribute("display", ""); 57 | if(!isborrow) 58 | { 59 | sb.append("
    此学生没有借书!
    "); 60 | session.setAttribute("display", "none"); 61 | } 62 | 63 | 64 | session.setAttribute("studentinfo", sb.toString()); 65 | response.sendRedirect("admin/amdin_borrowInfo.jsp"); 66 | } 67 | 68 | /** 69 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 70 | */ 71 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 72 | // TODO Auto-generated method stub 73 | doGet(request, response); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /servlet/SetEncoding.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.Filter; 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.FilterConfig; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.ServletRequest; 9 | import javax.servlet.ServletResponse; 10 | import javax.servlet.annotation.WebFilter; 11 | 12 | /** 13 | * Servlet Filter implementation class SetEncoding 14 | */ 15 | @WebFilter("/*") 16 | public class SetEncoding implements Filter { 17 | 18 | /** 19 | * Default constructor. 20 | */ 21 | public SetEncoding() { 22 | // TODO Auto-generated constructor stub 23 | } 24 | 25 | /** 26 | * @see Filter#destroy() 27 | */ 28 | public void destroy() { 29 | // TODO Auto-generated method stub 30 | } 31 | 32 | /** 33 | * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) 34 | */ 35 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 36 | // TODO Auto-generated method stub 37 | // place your code here 38 | 39 | request.setCharacterEncoding("utf-8"); 40 | response.setCharacterEncoding("utf-8"); 41 | chain.doFilter(request, response); 42 | } 43 | 44 | /** 45 | * @see Filter#init(FilterConfig) 46 | */ 47 | public void init(FilterConfig fConfig) throws ServletException { 48 | // TODO Auto-generated method stub 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /servlet/ShowBookInfo.java: -------------------------------------------------------------------------------- 1 | package com.henu.servlet; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | 14 | import com.henu.bean.Info; 15 | import com.henu.factory.DaoFactory; 16 | 17 | /** 18 | * Servlet implementation class ShowBookInfo 19 | */ 20 | @WebServlet("/ShowBookInfo") 21 | public class ShowBookInfo extends HttpServlet { 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** 25 | * @see HttpServlet#HttpServlet() 26 | */ 27 | public ShowBookInfo() { 28 | super(); 29 | // TODO Auto-generated constructor stub 30 | } 31 | 32 | /** 33 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 34 | */ 35 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 36 | doPost(request, response); 37 | } 38 | 39 | /** 40 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 41 | */ 42 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 43 | HttpSession session = request.getSession(); 44 | String id = (String)session.getAttribute("studentId"); 45 | List list = new ArrayList<>(); 46 | list = DaoFactory.getStudentDaoImpl().findById(id); 47 | StringBuilder sb = new StringBuilder(); 48 | for (Info info : list) { 49 | sb.append(""+info.getBookname()+""); 50 | sb.append(""+info.getDays()+""); 51 | sb.append(""+info.getCon()+""); 52 | sb.append(""+info.getDate()+""); 53 | sb.append("还书"); 54 | } 55 | 56 | session.setAttribute("bookinfo", sb.toString()); 57 | response.sendRedirect("student/student_Message.jsp"); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /tool/DesUtils.java: -------------------------------------------------------------------------------- 1 | package com.henu.tool; 2 | 3 | import java.security.Key; 4 | import java.security.Security; 5 | 6 | import javax.crypto.Cipher; 7 | 8 | /** 9 | * DES加密和解密工具,对字符串进行加密和解密操作 10 | * 11 | * 12 | * 13 | */ 14 | public class DesUtils { 15 | 16 | /** 字符串默认键值 */ 17 | private static String strDefaultKey = "national"; 18 | 19 | /** 加密工具 */ 20 | private Cipher encryptCipher = null; 21 | 22 | /** 解密工具 */ 23 | private Cipher decryptCipher = null; 24 | 25 | /** 26 | * 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[] 27 | * hexStr2ByteArr(String strIn) 互为可逆的转换过程 28 | */ 29 | public static String byteArr2HexStr(byte[] arrB) throws Exception { 30 | int iLen = arrB.length; 31 | // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍 32 | StringBuffer sb = new StringBuffer(iLen * 2); 33 | for (int i = 0; i < iLen; i++) { 34 | int intTmp = arrB[i]; 35 | // 把负数转换为正数 36 | while (intTmp < 0) { 37 | intTmp = intTmp + 256; 38 | } 39 | // 小于0F的数需要在前面补0 40 | if (intTmp < 16) { 41 | sb.append("0"); 42 | } 43 | sb.append(Integer.toString(intTmp, 16)); 44 | } 45 | return sb.toString(); 46 | } 47 | 48 | /** 49 | * 将表示16进制值的字符串转换为byte数组, 和public static String byteArr2HexStr(byte[] arrB) 50 | * 互为可逆的转换过程 51 | */ 52 | // 解密 53 | public static byte[] hexStr2ByteArr(String strIn) throws Exception { 54 | byte[] arrB = strIn.getBytes(); 55 | int iLen = arrB.length; 56 | 57 | // 两个字符表示一个字节,所以字节数组长度是字符串长度除以2 58 | byte[] arrOut = new byte[iLen / 2]; 59 | for (int i = 0; i < iLen; i = i + 2) { 60 | String strTmp = new String(arrB, i, 2); 61 | arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); 62 | } 63 | return arrOut; 64 | } 65 | 66 | /** 67 | * 默认构造方法,使用默认密钥 68 | */ 69 | public DesUtils() throws Exception { 70 | this(strDefaultKey); 71 | } 72 | 73 | /** 74 | * 指定密钥构造方法 75 | */ 76 | public DesUtils(String strKey) throws Exception { 77 | Security.addProvider(new com.sun.crypto.provider.SunJCE()); 78 | Key key = getKey(strKey.getBytes()); 79 | 80 | encryptCipher = Cipher.getInstance("DES"); 81 | encryptCipher.init(Cipher.ENCRYPT_MODE, key); 82 | 83 | decryptCipher = Cipher.getInstance("DES"); 84 | decryptCipher.init(Cipher.DECRYPT_MODE, key); 85 | } 86 | 87 | /** 88 | * 加密字节数组 89 | */ 90 | public byte[] encrypt(byte[] arrB) throws Exception { 91 | return encryptCipher.doFinal(arrB); 92 | } 93 | 94 | /** 95 | * 加密字符串 96 | */ 97 | public String encrypt(String strIn) throws Exception { 98 | return byteArr2HexStr(encrypt(strIn.getBytes())); 99 | } 100 | 101 | /** 102 | * 解密字节数组 103 | */ 104 | public byte[] decrypt(byte[] arrB) throws Exception { 105 | return decryptCipher.doFinal(arrB); 106 | } 107 | 108 | /** 109 | * 解密字符串 110 | */ 111 | public String decrypt(String strIn) throws Exception { 112 | return new String(decrypt(hexStr2ByteArr(strIn))); 113 | } 114 | 115 | /** 116 | * 从指定字符串生成密钥,密钥所需的字节数组长度为8位 不足8位时后面补0,超出8位只取前8位 117 | */ 118 | private Key getKey(byte[] arrBTmp) throws Exception { 119 | // 创建一个空的8位字节数组(默认值为0) 120 | byte[] arrB = new byte[8]; 121 | 122 | // 将原始字节数组转换为8位 123 | for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) { 124 | arrB[i] = arrBTmp[i]; 125 | } 126 | 127 | // 生成密钥 128 | Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES"); 129 | 130 | return key; 131 | } 132 | 133 | //加密 134 | public static String jiami(String s){ 135 | String result = ""; 136 | try { 137 | DesUtils des = new DesUtils("leemenz"); //自定义秘钥 138 | result = des.encrypt(s); 139 | } catch (Exception e) { 140 | // TODO Auto-generated catch block 141 | e.printStackTrace(); 142 | } 143 | return result; 144 | } 145 | 146 | //解密 147 | public static String jiemi(String s){ 148 | String result = ""; 149 | 150 | try { 151 | DesUtils des = new DesUtils("leemenz"); //自定义秘钥 152 | result = des.decrypt(s); 153 | } catch (Exception e) { 154 | e.printStackTrace(); 155 | } 156 | return result; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /tool/GetBookData.java: -------------------------------------------------------------------------------- 1 | package com.henu.tool; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import com.henu.Db.DbUtil; 12 | import com.henu.bean.Book; 13 | 14 | import jxl.Sheet; 15 | import jxl.Workbook; 16 | import jxl.read.biff.BiffException; 17 | 18 | public class GetBookData { 19 | public static List getAllByExcel(String path) throws IOException { 20 | if (path == null) 21 | path = "D:\\Book.xls"; 22 | File filePath = new File(path); 23 | List list = new ArrayList<>(); 24 | 25 | try { 26 | Workbook wb = Workbook.getWorkbook(filePath); 27 | //得到文件中第一个工作表格,若要得到全部用sheet[] sheets = wb.getSheets() 28 | Sheet sheet = wb.getSheet(0); 29 | 30 | //得到第一个表中的总行数和列数 31 | int rows = sheet.getRows(); 32 | int cols = sheet.getColumns(); 33 | //循环取出表中的所有数据,第一行一般是标题,所有循环从1开始而不是0 34 | for (int i = 1; i < rows; i++) { 35 | for (int j = 0; j < cols; j++) { 36 | String bookname = sheet.getCell(j++, i).getContents(); 37 | String author = sheet.getCell(j++, i).getContents(); 38 | String press = sheet.getCell(j++, i).getContents(); 39 | String pubdate = sheet.getCell(j++, i).getContents(); 40 | String type = sheet.getCell(j++, i).getContents(); 41 | String bookshelf = sheet.getCell(j++, i).getContents(); 42 | int count = Integer.parseInt(sheet.getCell(j++, i).getContents()); 43 | 44 | 45 | list.add(new Book(bookname,author,press,pubdate,type,bookshelf,count)); 46 | } 47 | } 48 | } catch (BiffException e) { 49 | e.printStackTrace(); 50 | } 51 | return list; 52 | } 53 | 54 | public static boolean isExist(String bookname){ 55 | String sql = "select * from book where bookname = ?"; 56 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 57 | ResultSet rs = null; 58 | 59 | try { 60 | ps.setString(1, bookname); 61 | rs = ps.executeQuery(); 62 | if(rs.next()) 63 | return true; 64 | else 65 | return false; 66 | } catch (SQLException e) { 67 | return false; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tool/GetStudentData.java: -------------------------------------------------------------------------------- 1 | package com.henu.tool; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import com.henu.Db.DbUtil; 12 | import com.henu.bean.Student; 13 | 14 | import jxl.Sheet; 15 | import jxl.Workbook; 16 | import jxl.read.biff.BiffException; 17 | 18 | public class GetStudentData { 19 | public static List getAllByExcel(String path) throws IOException { 20 | if (path == null || path.equals("")) 21 | path = "D:\\Test.xls"; 22 | File filePath = new File(path); 23 | List list = new ArrayList<>(); 24 | 25 | try { 26 | Workbook wb = Workbook.getWorkbook(filePath); 27 | //得到文件中第一个工作表格,若要得到全部用sheet[] sheets = wb.getSheets() 28 | Sheet sheet = wb.getSheet(0); 29 | 30 | //得到第一个表中的总行数和列数 31 | int rows = sheet.getRows(); 32 | int cols = sheet.getColumns(); 33 | 34 | //循环取出表中的所有数据,第一行一般是标题,所以循环从1开始而不是0 35 | for (int i = 1; i < rows; i++) { 36 | for (int j = 0; j < cols; j++) { 37 | String id = sheet.getCell(j++, i).getContents(); 38 | String name = sheet.getCell(j++, i).getContents(); 39 | String gender = sheet.getCell(j++, i).getContents(); 40 | String phone = sheet.getCell(j++, i).getContents(); 41 | String email = sheet.getCell(j++, i).getContents(); 42 | String department = sheet.getCell(j++, i).getContents(); 43 | 44 | list.add(new Student(id, name,gender,phone,email,department,0)); 45 | } 46 | } 47 | } catch (BiffException e) { 48 | e.printStackTrace(); 49 | } 50 | return list; 51 | } 52 | 53 | public static boolean isExist(String id){ 54 | String sql = "select * from student where id = ?"; 55 | PreparedStatement ps = DbUtil.executePreparedStatement(sql); 56 | ResultSet rs = null; 57 | try { 58 | ps.setString(1, id); 59 | rs = ps.executeQuery(); 60 | int i = rs.getRow(); 61 | 62 | if(rs.next()) 63 | return true; 64 | else 65 | return false; 66 | } catch (SQLException e) { 67 | return true; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tool/SendMail.java: -------------------------------------------------------------------------------- 1 | package com.henu.tool; 2 | 3 | import com.henu.service.UserManager; 4 | 5 | public class SendMail implements Runnable{ 6 | 7 | private String username; 8 | private String password; 9 | private String email; 10 | UserManager userManager; 11 | public SendMail(String username,String password,String email,UserManager userManager) { 12 | this.username = username; 13 | this.password = password; 14 | this.email = email; 15 | this.userManager = userManager; 16 | } 17 | 18 | @Override 19 | public void run() { 20 | userManager.Register(username, password, email); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /数据库代码及sql文件.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sduwfc/Java_BookManagemant/6e522e6aa0d3d6016d1cba7adb975d3fd61493d5/数据库代码及sql文件.zip --------------------------------------------------------------------------------