JSP學(xué)生信息管理系統(tǒng)設(shè)計(jì)
本文實(shí)例為大家分享了jsp學(xué)生信息管理系統(tǒng)源碼,供大家參考,具體內(nèi)容如下
新建學(xué)生信息數(shù)據(jù)庫(kù)
1.添加記錄模塊
<%@ page contenttype="text/html" pageencoding="utf-8"%> <html> <head> <title>添加新學(xué)生</title> </head> <body> <form action="stuinsert2.jsp" method="post"> <table border="0" width="238" heigth="252"> <tr><td>學(xué)號(hào):</td><td><input type="text" name="id"></td></tr> <tr><td>姓名</td><td><input type="text" name="name"></td></tr> <tr><td>性別</td><td><input type="text" name="sex"></td></tr> <tr><td>年齡</td><td><input type="text" name="age"></td></tr> <tr><td>專業(yè)</td><td><input type="text" name="sdept"></td></tr> <tr align="center"> <td colspan="2"> <input type="submit" value="提交"> <input type="reset" value="取消"> </td> </tr> </table> </form> </body> </html>
<%@ page language="java" import="java.sql.*" pageencoding="utf-8"%> <html> <head> <title>添加學(xué)生處理程序</title> </head> <body> <% class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); string url="jdbc:sqlserver://localhost:1433; databasename=p"; string user="sa"; string password="123456"; connection conn=drivermanager.getconnection(url,user,password); request.setcharacterencoding("utf-8"); string id=request.getparameter("id"); string name=request.getparameter("name"); string sex=request.getparameter("sex"); int age=integer.parseint(request.getparameter("age")); string sdept=request.getparameter("sdept"); string sql=string.format("select * from student where sno=%s",id); statement stmt=conn.createstatement(); preparedstatement pstmt; resultset rs=stmt.executequery(sql); if(!(rs.next())){ pstmt=conn.preparestatement("insert into student values(?,?,?,?,?)"); pstmt.setstring(1,id); pstmt.setstring(2,name); pstmt.setstring(3,sex); pstmt.setint(4,age); pstmt.setstring(5,sdept); pstmt.executeupdate(); out.print("添加成功"); %> <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >返回菜單</a><br> <a href="main.jsp" rel="external nofollow" ></a> <%}else{ out.println("該學(xué)號(hào)已存在");%> <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >重新添加</a> <%}%> </body> </html>
2.查詢(all)模塊
<%@ page language="java" import="java.sql.*" pageencoding="utf-8"%> <%@ page import="javax.sql.*" %> <%@ page import="javax.naming.*" %> <html> <head> <title>信息查看頁(yè)面</title> </head> <body> <center> <% datasource ds=null; initialcontext ctx=new initialcontext(); ds=(datasource)ctx.lookup("java:comp/env/jdbc/sqlserver"); connection conn=ds.getconnection(); preparedstatement pstmt=conn.preparestatement("select * from student"); resultset rs=pstmt.executequery(); %> <table border="2" bgcolor="ccceee" width="650"> <tr bgcolor="cccccc" align="center"> <td>記錄條數(shù)</td><td>學(xué)號(hào)</td><td>姓名</td> <td>性別</td><td>年齡</td><td>專業(yè)</td> </tr> <% while(rs.next()){ %> <tr align="center"> <td><%=rs.getrow()%></td> <td><%=rs.getstring(1)%></td> <td><%=rs.getstring(2)%></td> <td><%=rs.getstring(3)%></td> <td><%=rs.getstring(4)%></td> <td><%=rs.getstring(5)%></td> </tr> <%}%> </center> <%if(rs!=null){rs.close();} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} %> </table> </body> </html>
條件查詢模塊
<%@ page language="java" pageencoding="utf-8"%> <html> <head> <title>my jsp 'stufind2.jsp' starting page</title> </head> <body> 請(qǐng)選擇查詢條件<hr width="100%" size="3"> <form action="stufind3.jsp" method="post"> 性別<input type="radio" value="男" name="sex" checked="checked">男 <input type="radio" value="女" name="sex">女 年齡范圍:<p> 最?。?lt;input type="text" name="a1"><br><br> 最大:<input type="text" name="a2"><p> <input type="submit" value="提交"> <input type="reset" value="取消"> </form> </body> </html>
<%@ page contenttype="text/html" import="java.sql.*" pageencoding="utf-8"%> <html> <head> <title>條件查詢處理頁(yè)面</title> </head> <body> <center> <%class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); string user="sa"; string password="123456"; string url="jdbc:sqlserver://localhost:1433;databasename=p"; connection conn=drivermanager.getconnection(url,user,password); request.setcharacterencoding("utf-8"); string sex=request.getparameter("sex"); int age1=integer.parseint(request.getparameter("a1")); int age2=integer.parseint(request.getparameter("a2")); string sql="select * from student where ssex=? and sage>=? and sage<=?"; preparedstatement pstmt=conn.preparestatement(sql); pstmt.setstring(1,sex); pstmt.setint(2,age1); pstmt.setint(3,age2); resultset rs=pstmt.executequery(); %> <table border="2" bgcolor="ccceee" width="650"> <tr bgcolcor="cccccc" align="center"> <td>記錄條數(shù)</td><td>學(xué)號(hào)</td><td>姓名</td> <td>性別</td><td>年齡</td><td>專業(yè)</td> </tr> <%while(rs.next()){ %> <tr align="center"> <td><%=rs.getrow()%></td> <td><%=rs.getstring(1)%></td> <td><%=rs.getstring(2)%></td> <td><%=rs.getstring(3)%></td> <td><%=rs.getstring(4)%></td> <td><%=rs.getstring(5)%></td> </tr> <%}%> </table> <%if(rs!=null){rs.close();} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} %> </center> </body> </html>
3.修改模塊
<%@ page language="java" import="java.util.*" pageencoding="utf-8"%> <html> <head> <title>修改提交頁(yè)面</title> </head> <body> <center> 請(qǐng)選擇修改記錄所滿足的條件 <form action="stuupdate2.jsp" method="post"> 姓名: <input type="text" name="name"><br><br> 性別: 男<input type="radio" value="男" name="sex"> 女<input type="radio" value="女" name="sex"><br><br> <input type="submit" value="提交"> <input type="reset" value="取消"> </form> </center> </body> </html>
<%@ page contenttype="text/html" import="java.sql.*" pageencoding="utf-8"%> <html> <head> <title>修改編輯頁(yè)面</title> </head> <body> <% class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); string user="sa"; string password="123456"; string url="jdbc:sqlserver://localhost:1433;databasename=p"; connection conn=drivermanager.getconnection(url,user,password); request.setcharacterencoding("utf-8"); string name=request.getparameter("name"); string sex=request.getparameter("sex"); session.setattribute("sex",sex); session.setattribute("name",name); string sql="select * from student where ssex=? and sname=?"; preparedstatement pstmt=conn.preparestatement(sql); pstmt.setstring(1,sex); pstmt.setstring(2,name); resultset rs=pstmt.executequery(); if(rs.next()){ string id=rs.getstring("sno"); string name2=rs.getstring("sname"); string sex2=rs.getstring("ssex"); int age=rs.getint("sage"); string sdept=rs.getstring("sdept"); if(pstmt!=null){pstmt.close();} if(rs!=null){rs.close();} if(conn!=null){conn.close();} %> <form action="stuupdate3.jsp" method="post"> <table border="0" width="238" height="252"> <tr><td>學(xué)號(hào):</td><td><input type="text" name="id" value=<%=id%>></td></tr> <tr><td>姓名:</td><td><input type="text" name="name2" value=<%=name2%>></td></tr> <tr><td>性別:</td><td><input type="text" name="sex2" value=<%=sex2%>></td></tr> <tr><td>年齡:</td><td><input type="text" name="age" value=<%=age%>></td></tr> <tr><td>專業(yè):</td><td><input type="text" name="sdept" value=<%=sdept%>></td></tr> <tr align="center"> <td colspan="2"> <input type="submit" value="提交"> <input type="reset" value="取消"> </td> </tr> </table> </form> <%} else{%> 沒有找到合適條件的記錄??!<% if(rs!=null){rs.close();} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} }%> </body> </html>
<%@ page language="java" import="java.sql.*" pageencoding="utf-8"%> <html> <head> <title>修改后重寫頁(yè)面</title> </head> <body> <% class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); string url="jdbc:sqlserver://localhost:1433; databasename=p"; string user="sa"; string password="123456"; connection conn=drivermanager.getconnection(url,user,password); string sql="update student set sno=?,sname=?,ssex=?,sage=?,sdept=? where sname=? and ssex=?"; preparedstatement pstmt=conn.preparestatement(sql); request.setcharacterencoding("utf-8"); string id=request.getparameter("id"); string name2=request.getparameter("name2"); string sex2=request.getparameter("sex2"); int age=integer.parseint(request.getparameter("age")); string sdept=request.getparameter("sdept"); string name=(string)session.getattribute("name"); string sex=(string)session.getattribute("sex"); pstmt.setstring(1,id); pstmt.setstring(2,name2); pstmt.setstring(3,sex2); pstmt.setint(4,age); pstmt.setstring(5,sdept); pstmt.setstring(6,name); pstmt.setstring(7,sex); int n=pstmt.executeupdate(); if(n>=1){%>重寫數(shù)據(jù)庫(kù)操作成功!<br><%} else{%>重寫數(shù)據(jù)庫(kù)操作失??!<br><%} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} %> </body> </html>
4.刪除記錄模塊
<%@ page language="java" import="java.util.*" pageencoding="utf-8"%> <html> <head> <title>條件刪除提交頁(yè)面</title> </head> <body> 請(qǐng)選擇刪除記錄條件<<hr width="100%" size="3"> <form action="studelete2.jsp" method="post"> 姓名:<input type="text" name="name"><br><br> 性別:男<input type="radio" value="男" name="sex"> 女<input type="radio" value="女" name="sex"><br><br> 年齡范圍:<br><p> 最小:<input type="text" name="a1"><br> 最大:<input type="text" name="a2"> </p> <input type="submit" value="提交"> <input type="reset" value="取消"> </form> </body> </html>
<%@ page language="java" import="java.sql.*" pageencoding="utf-8"%> <html> <head> <title>條件刪除處理頁(yè)面</title> </head> <body> <% class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); string user="sa"; string password="123456"; string url="jdbc:sqlserver://localhost:1433;databasename=p"; connection conn=drivermanager.getconnection(url,user,password); request.setcharacterencoding("utf-8"); string name=request.getparameter("name"); string sex=request.getparameter("sex"); string ag1=request.getparameter("a1"); string ag2=request.getparameter("a2"); int a3,a4; string sql="delete from student where sname=? and ssex=? and sage>=? and sage<=?"; preparedstatement pstmt=conn.preparestatement(sql); if(!name.equals("")) pstmt.setstring(1,name); if(sex!=null) pstmt.setstring(2,sex); if(!ag1.equals("")){a3=integer.parseint(ag1); pstmt.setint(3,a3);} if(!ag2.equals("")){a4=integer.parseint(ag2); pstmt.setint(4,a4);} int n=pstmt.executeupdate(); if(n==1){%>數(shù)據(jù)刪除成功<br><%} else{%>數(shù)據(jù)刪除失??!<br><%} if(pstmt!=null){pstmt.close();} if(conn!=null){conn.close();} %> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持碩編程。
相關(guān)文章
- jsp+servlet實(shí)現(xiàn)文件上傳與下載功能
- EJB3.0部署消息驅(qū)動(dòng)Bean拋javax.naming.NameNotFoundException異常
- 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法
- 秒殺系統(tǒng)Web層設(shè)計(jì)的實(shí)現(xiàn)方法
- 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法
- JSP使用過(guò)濾器防止Xss漏洞
- 在JSP頁(yè)面中動(dòng)態(tài)生成圖片驗(yàn)證碼的方法實(shí)例
- 詳解JSP 內(nèi)置對(duì)象request常見用法
- 使用IDEA編寫jsp時(shí)EL表達(dá)式不起作用的問(wèn)題及解決方法
- jsp實(shí)現(xiàn)局部刷新頁(yè)面、異步加載頁(yè)面的方法
- Jsp中request的3個(gè)基礎(chǔ)實(shí)踐
- JavaServlet的文件上傳和下載實(shí)現(xiàn)方法
- JSP頁(yè)面的靜態(tài)包含和動(dòng)態(tài)包含使用方法