Implementation of student information management system with Java Web

This paper shares the student information management system implemented by Java Web for your reference. The specific contents are as follows

Initial version

The initial version does not add pagination. Because I haven't learned much about the front end, the interface is ugly. Main technologies: JSP, JavaBean, servlet and JDBC. The main pages are as follows:

Login page

homepage

Add student

View all students

Query students

Project catalogue

database

Two tables, user table and student table. In order to use the dbutils tool, you must pay attention to the matching between the name of the attributes of the database table and the get() set() method of the JavaBean. Like t_ The uname in the user table in JavaBean is: private string uname, getuname(), setuname().

Little knowledge

Sign in

When logging in, whether the user name or password input box is empty is determined by the JS code on the login page. If neither is empty, query the database through the user name information. If the user is found, log in successfully. Otherwise, judge whether the user name or password is wrong. This transaction is handled in the service layer, and the Dao layer is only responsible for finding users through user names.

Userservice Code:

Filter filter

In order to prevent users who are not logged in from directly accessing other pages, a filter needs to be written. All pages except the login page are placed in a users folder separately. When the user logs in successfully, the user's information is saved to the "sessionuser" attribute of the session. The filter determines whether this attribute is empty. If it is empty, the user's login is unsuccessful and will not be released. Go directly to the login page. If it is not empty, it will be released. Main code of filter:

Multi condition combined query

On the advanced search page, there are four options: student name, gender, mobile phone number and email. The four conditions can be arranged and combined arbitrarily. This problem was also encountered when writing QT projects before. At that time, we used to splice SQL statements, but we didn't expect to use "where 1 = 1", which was very troublesome. The following code is classic and uses fuzzy query to make the search more humanized.

Evolution: paging

The queried pages will be displayed, which is more beautiful. Page form: page n of M page 1 2 3 4 5 6 7 8 9 10 last page of the first page.

The paging effect is as follows:

Data required for paging:

Current page: pagecode total pages: totalpage total records: totalrecord records per page: PageSize current page data: beanlist

PageBean

Because these paging data always have to be transferred back and forth between layers! We encapsulate these paging data into a java bean, which is called a paging bean, such as pagebean. When you click Page 2 after using multi criteria query, the hyperlink on page 2 has no query criteria and will lose the query criteria, so we need to keep the query criteria for all links on the page! We want to save the condition as a string to the URL of pagebean! The code is as follows:

Processing of paging in each layer

JSP page: display data and "page n / page m of m first page Previous page 1 2 3 4 5 6 7 8 9 10 last page of the next page"; Pass pagecode to servlet servlet: create pagebean object, assign values to all properties of pagebean, and then pass pagecode and PageSize to Dao layer; Accept the pagebean object returned by the Dao, save it to the request field, and return it to the page service: act as an intermediary, and there is no transaction to process. Dao: get the pagecode and PageSize, create the pagebean object, query the database to get totalrecord and beanlist, and return the pagebean.

JSP page processing code:

Multi condition combined query code after Pagination

For more learning materials, please pay attention to the special topic "management system development".

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>