Student management System (JSP+MYSQL)

Source: Internet
Author: User
Tags java web

1, the purpose of the experiment

by using Java Web Technology design a simple database management system, understand the difference between the foreground page and the background editing page, master the WEB server and MySQL database connection and database operation method, master the method of writing backstage code using JSP.

2. Experimental content and requirements

develop a student management system to complete the functions of viewing, adding, deleting and modifying student information. for client additions and modifications to the information page, use JavaScript to perform non-null validation of the necessary data. Add some CSS yourself to make the page and font more beautiful.  

3. Experimental steps and experimental results

(1) Open MySQL and create a new database named Studentmanagement.  

(2) Create a new database table named Student, with the school number, name, gender, date of birth, address and other information, self-defined column name and type.  

(3) add several records to the Student table as the initial data.  

(4) open the Eclipse software and create a new Web project named LAB03.  

(5) write the code in LAB03.  

(6) You can practice to define some CSS, make the page and font more beautiful.  

Experimental results:

(Listed below: folder structure, List of all files, feature description, code, and running results)

1. folder structure diagram

2. list of all files

1. Function Description

1. Realization of Student information management system simulation

2. Can be connected to the database for data deletion and re-search

3. can add a student information

4. You can delete a student's information

5. You can change a student's information

4. Code

<%@ page contenttype="text/html; charset=gb2312 " import=" java.sql.* " errorpage=" error.jsp "%>

<link rel="stylesheet" type="Text/css " href="Mystyle.css" >

<title> Add student Information </title>

<body>

<form action="add.jsp " method="POST">

<table Align="center" width="50%" border="1" >

<caption style= "font-size: 24px" > Add student Information </caption>

<tr>

<th width="30%" height="111" style= "font-size: 24px" > Study No.:</th>

<TD width="70%"><input name="number" type="text"></td>

</tr>

<tr>

<th height=" style=" font-size: 24px"> Name:</th>

<td><input name="name" type="text"></td>

</tr>

<tr>

<th height=" style=" font-size: 24px"> Sex:</th>

<td><input name="Sex " type="text"></td>

</tr>

<tr>

<th height="107" style= "font-size: 24px" > Date of birth:</th>

<td><input name="date" type="text"></td>

</tr>

<tr>

<th height="113" style= "font-size: 24px" > Address:</th>

<td><input name="adress " type="text"></td>

</tr>

<tr>

<th colspan="2">

<input type="Submit " Name="Submit " value=" add ">

<input type=" reset" value=" Reset" >

</th>

</tr>

</table>

</form>

<%

Request.setcharacterencoding ("gb2312");

String Submit=request.getparameter ("submit");

if (submit!=null&&!submit.equals (""))

{

String Number=request.getparameter ("number");

String name=request.getparameter ("name");

String sex=request.getparameter ("sex");

String date=request.getparameter ("date");

String adress=request.getparameter ("adress");

Class.forName ("Com.mysql.jdbc.Driver");

Connection con=drivermanager.getconnection ("jdbc:mysql://localhost:3306/studentmanagement?useunicode=true& Characterencoding=gb2312 "," root "," Yubaba ");

Statement stmt=con.createstatement ();

String sql= "INSERT into student (number,name,sex,date,adress) VALUES ('" +number+ "', '" +name+ "', '" +sex+ "', '" +date+ "', ' "+adress+") ";

int i=stmt.executeupdate (SQL);

if (i==1)

{

Out.println ("<script language= ' JavaScript ' > Alert (' add success , Click OK to jump to homepage ! '); </script> ");

Response.setheader ("Refresh", "1;url=index.jsp");

}

Else {

Out.println ("<script language= ' JavaScript ' > Alert (' add failed, click OK to return to the add page! ');</script> ");

Response.setheader ("Refresh", "1;url=add.jsp");

}

Stmt.close ();

Con.close ();

}

%>

</body>

<%@ page import="java.sql.*" pageencoding="gb2312" errorpage="error.jsp"%>

<link rel="stylesheet" type="Text/css " href="Mystyle.css" >

<title> Modify Student Information </title>

<body>

<%

Request.setcharacterencoding ("gb2312");

Class.forName ("Com.mysql.jdbc.Driver");

Connection con=drivermanager.getconnection ("jdbc:mysql://localhost:3306/studentmanagement?useunicode=true& Characterencoding=gb2312 "," root "," Yubaba ");

Statement stmt=con.createstatement ();

String id=request.getparameter ("id");

ResultSet rs=stmt.executequery ("select * from student where id=" +id);

Rs.next ();

%>

<form action="update.jsp " method="POST">

<table Align="center" width="50%" border="1">

<caption style= "font-size: 24px" > Edit student Information </caption>

<tr>

<th width="30%" height="123" style= "font-size: 24px" > Study No.:</th>

<TD width="70%"><input name="number" type="text" value="<%= Rs.getstring (2)%>"></td>

</tr>

<tr>

<th height="103" style= "font-size: 24px" > Name:</th>

<td><input name="name" type="text" value="<%=rs.getstring (3)%> "></td>

</tr>

<tr>

<th height= "style=" font-size: 24px"> Sex:</th>

<td><input name="Sex" type="text" value="<%=rs.getstring (4)%>" ></td>

</tr>

<tr>

<th height=" style=" font-size: 24px"> Date of birth:</th>

<td><input name="date" type="text" value="<%=rs.getstring (5)%>" ></td>

</tr>

<tr>

<th height=" style=" font-size: 24px"> Address:</th>

<td><input name="adress" type="text" value="<%=rs.getstring (6)%>" ></td>

</tr>

<tr>

<th colspan="2">

<input type="hidden" name="id" value="<%=id%>">

<input type="Submit" value=" modify ">

<input type=" reset" value=" Reset" >

</th>

</tr>

</table>

</form>

<%

Rs.close ();

Stmt.close ();

Con.close ();

%>

</body>

<%@ page language="java" import="java.sql.*" pageencoding="gb2312"%>

<%@ page errorpage="error.jsp"%>

<link rel="stylesheet" type="Text/css " href="Mystyle.css" >

<title> Student Management Systems </title>

<body>

<Center><a href=add.jsp style="font-size: 24px">Add student Information</a></Center><p>

<table Align="center" width="50%" border=1>

<tr><th height=" style=" font-size: 16px"> Study No. </th><th style=" Font-size: 16px"> Name </th><th style=" font-size: 16px"> Gender </th><th style=" Font-size: 16px"> Date of birth </th><th style=" font-size: 16px"> Address </th><th style=" Font-size: 16px> Management </th>

<%

Class.forName ("Com.mysql.jdbc.Driver");

Connection con=drivermanager.getconnection ("jdbc:mysql://localhost:3306/studentmanagement?useunicode=true& Characterencoding=gb2312 "," root "," Yubaba ");

Statement stmt=con.createstatement ();

String s= "SELECT * from student";

ResultSet Rs=stmt.executequery (s);

while (Rs.next ())

{

int id=rs.getint (1);

Out.println ("<tr><td>" +rs.getstring (2) + "</td><td>" +rs.getstring (3) + "</TD><TD > "+rs.getstring (4) +" </td><td> "+rs.getstring (5) +" </td><td> "+rs.getstring (6) +" </td ><td><a href= ' edit.jsp?id= "+id+" ' > modify </a> <a href= ' del.jsp?id=' +id+ ' > Delete </a></td></tr> ");

}

Rs.close ();

Stmt.close ();

Con.close ();

%>

</table>

</body>

5. Running

4. Experiment Experience

1. Connect to the database to pay attention to the database name and table name can not be wrong, and garbled is to refer to the page default encoding type, when connecting to the database set your default encoding type such as:? characterencoding=gb2312

2. Adding or deleting changes to the page to master the jump

3.CSS outer style is more convenient, can be used more later, more familiar with

Student management System (JSP+MYSQL)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.