朱泓錦20136239《J2EE程序設(shè)計(jì)》實(shí)驗(yàn)1_第1頁
朱泓錦20136239《J2EE程序設(shè)計(jì)》實(shí)驗(yàn)1_第2頁
朱泓錦20136239《J2EE程序設(shè)計(jì)》實(shí)驗(yàn)1_第3頁
朱泓錦20136239《J2EE程序設(shè)計(jì)》實(shí)驗(yàn)1_第4頁
朱泓錦20136239《J2EE程序設(shè)計(jì)》實(shí)驗(yàn)1_第5頁
已閱讀5頁,還剩24頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、天津理工大學(xué)實(shí)驗(yàn)報(bào)告學(xué)院(系)名稱:計(jì)算機(jī)與通信工程學(xué)院姓名朱泓錦學(xué)號20136239專業(yè)物聯(lián)網(wǎng)工程班級2實(shí)驗(yàn)項(xiàng)目實(shí)驗(yàn)一 J2EE Web應(yīng)用開發(fā)課程名稱J2EE程序設(shè)計(jì)課程代碼0660266實(shí)驗(yàn)時間2015.5實(shí)驗(yàn)地點(diǎn)7-215批改意見成績教師簽字: 實(shí)驗(yàn)內(nèi)容: 實(shí)現(xiàn)一個基于JSP技術(shù)的小型管理系統(tǒng),主題自擬。1、采用JSP和JDBC實(shí)現(xiàn)用戶登錄功能。數(shù)據(jù)庫采用MySQL。2、采用Session實(shí)現(xiàn)用戶身份驗(yàn)證。3、實(shí)現(xiàn)對數(shù)據(jù)庫記錄的增刪改查。第29頁 共29頁一登錄頁面05.php的代碼如下:<?php session_start() ; /初始化sessionif (isset (

2、$_SESSION'user')header ("Location:index.php") ; /重新定向到其他頁面exit ; ?><script language="javascript">function checklogin ()if (login.username.value!="") && (login.password.value!="")return true /判斷用戶名和密碼不為空,返回TRUEelse alert ("用戶名或密碼不能

3、為空!") </script><style type="text/css">.style1 font-size: 13px; font-family: "黑體" font-weight: normal; color: #0099FF; </style><div align="center"><table width="260" border="1" bgcolor="#D8EFFA"><form na

4、me="login" method="post" action="06.php" onSubmit="return checklogin()"><tr align="center"><td height="30" colspan="2"><span class="style1">管理系統(tǒng)登錄</span></td></tr><tr><td w

5、idth="90" align="center" class="style1">管理員: </td><td width="170" height="20" align="left" valign="middle"><input name="username" type="text" id="username" size="20"><

6、;/td></tr><tr><td align="center" class="style1">密碼: </td><td height="20" align="left" valign="middle"><input name="password" type="password" id="password" size="20"></t

7、d></tr><tr><td align="center" class="style1">&nbsp ; </td><td height="20" align="center"><input type="submit" name="Submit" value="登 錄"></td></tr></form></table>&l

8、t;/div>二該程序是一個管理員登錄界面,首先初始化session,然后通過檢測session變量是否已經(jīng)注冊來檢測用戶是否已經(jīng)登錄過,如果登錄過,則無需再次登錄,直接定向到其他頁面。這里還使用了javascript來判斷是否輸入了用戶名和密碼。驗(yàn)證登錄的頁面06.php的代碼如下:<?php session_start () ; /初始sessionif (isset ($_SESSION'user')header ("Location:shili.php") ; /重新定向到其他頁面exit ; /登錄過的話立即結(jié)束$shili_name=

9、$_POST'username' ; /獲取參數(shù)$password=$_POST'password' ;/驗(yàn)證管理員名稱和密碼是否正確,這里采用直接驗(yàn)證,沒有連接數(shù)據(jù)庫if ($shili_name="mr" and $password="mrsoft")session_register ("shili") ; /注冊新的變量,保存當(dāng)前會話的昵稱$shili = $shili_name ;echo "<font color=red>登錄成功!</font>"

10、;header ("Location:index.php") ; /登錄成功重定向到管理頁面elseecho "<table width='100%' align=center><tr><td align=center>" ;echo "賬號或密碼錯誤,或者不是管理員賬號<br>" ;echo "<font color=red>登錄失敗!</font><br><a href='05.php'>請重新

11、輸入</a>"echo "</td></tr></table>" ; ?>該程序同樣是先通過session變量檢測用戶是否已經(jīng)登錄,如果沒有,則要對輸入的用戶名和密碼進(jìn)行驗(yàn)證,正確則注冊session變量,輸出登錄成功!。如不正確,則提示登錄失敗。這是一個簡單的用戶登錄驗(yàn)證的程序,通過session變量阻止了那些沒有登錄而直接瀏覽的用戶。如果想要對某個頁面限制瀏覽的用戶,可以使用同樣的方式,只要把如下的代碼放在該頁面的開頭即可:<?php session_start () ;if (!isset ($_S

12、ESSION'user')echo "<p align=center>" ;echo "<font color=#ff0000 size=5><strong><big>" ;echo "你沒有登錄,請<a href='login-form.php'>登錄</a>!" ;echo "</big></strong></font></p>" ;exit () ; ?>

13、;三增減刪除查詢<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DO

14、CTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>輸入學(xué)生信息界面</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" co

15、ntent="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="style

16、sheet" type="text/css" href="styles.css">-> <script type="text/javascript""> function validate() var id=document.forms0.id.value; var name=.value; var age=document.forms0.age.value; var major=document.forms0.major.value; if(id&l

17、t;=0) alert("學(xué)號不能為空,請輸入學(xué)號!"); return false; else if(name.length<=0) alert("姓名不能為空,請輸入姓名!"); return false; else if(age<=0) alert("請輸入合法年齡!"); return false; else if(major.length<=0) alert("專業(yè)不能為空,請輸入所學(xué)專業(yè)!"); return false; else return true; /document.get

18、ElementById("form").submit(); </script> </head> <body> <br> <center> <h2>學(xué)生信息輸入</h2><hr> <form action="insert.jsp" method="post" id="form" onSubmit="return validate()" ><h4> 學(xué)號:<input typ

19、e="text" name="id" class="required:true"></input><br></h4><h4> 姓名:<input type="text" name="name"></input><br></h4><h4> 年齡:<input type="text" name="age"></input>&

20、lt;br></h4><h4> 性別:<input type="radio" name="gender" value="男">男 <input type="radio" name="gender" value="女">女<br></h4><h4> 專業(yè):<input type="text" name="major"></input

21、><br></h4> <input type="submit" value="提交"/> </form> <a href=layout.jsp>查看已輸入信息</a> </center> </body></html>4.2 insert.jsp文件<% page language="java" import="java.util.*" pageEncoding="UTF-8"%

22、><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN&qu

23、ot;><html> <head> <base href="<%=basePath%>"> <title>插入學(xué)生信息</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires&

24、quot; content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css"

25、;>-> </head> <body> <% request.setCharacterEncoding("UTF-8"); String id=request.getParameter("id"); String name=request.getParameter("name"); System.out.println(name); String age=request.getParameter("age"); String gender=request.getParame

26、ter("gender"); String major=request.getParameter("major"); Connection conn=null; Statement stat=null; ResultSet rs=null; Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:localhost:1521:orcl" String user="scott" String pa

27、ssword="tiger" conn=DriverManager.getConnection(url,user,password); stat=conn.createStatement(); rs=stat.executeQuery("insert into student(id,name,age,gender,major)values("+id+",'"+name+"',"+age+",'"+gender+"','"+major+&

28、quot;')"); %> <center> <% if(rs.next() out.print("<br><h3>成功輸入!</h3>"); else out.print("<br><h3>輸入失??!</h3>"); %> <br> <a href=submit.jsp>返回信息輸入頁面</a> <a href=layout.jsp>進(jìn)入信息查詢頁面</a> </cen

29、ter> <% if(rs!=null) rs.close(); if(stat!=null) stat.close(); if(conn!=null) conn.close(); %> </body></html>4.3 layout.jsp文件<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%St

30、ring path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<

31、;%=basePath%>"> <title>學(xué)生信息</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="

32、keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body> <% response.setCh

33、aracterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); String id=request.getParameter("id"); String name=request.getParameter("name"); String age=request.getParameter("age"); String gender=request.getParameter("gender"); String ma

34、jor=request.getParameter("major"); Connection conn=null; Statement stat=null; ResultSet rs=null; Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:localhost:1521:orcl" String user="scott" String password="tiger" conn=Driv

35、erManager.getConnection(url,user,password); stat=conn.createStatement(); / stat.execute("insert into student(id,name,age,gender,major)values("+id+",'"+name+"',"+age+",'"+gender+"','"+major+"')"); rs=stat.executeQuery

36、("select * from student"); %> <br> <h2>學(xué)生信息</h2> <hr> <br> <h3>全部學(xué)生信息如下</h3> <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <tr> <td>學(xué)號</td> <td>

37、;姓名</td> <td>年齡</td> <td>性別</td> <td>專業(yè)</td> </tr> <% while(rs.next() out.print("<tr>"); out.print("<td>"+rs.getInt("id")+"</td>"); out.print("<td>"+rs.getString("name&qu

38、ot;)+"</td>"); out.print("<td>"+rs.getInt("age")+"</td>"); out.print("<td>"+rs.getString("gender")+"</td>"); out.print("<td>"+rs.getString("major")+"</td>");

39、%> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a></td> <td><a href="update3.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.print("</tr>"); %> </table> <br

40、> <form action="idselect.jsp" method="post"> <h3>按學(xué)號查詢:<input type="text" name="id" value="" title="學(xué)號不能為空" ></input> <input type="submit" value="查詢"/></h3> <br> </form>

41、 <form action="nameselect.jsp" method="post"> <h3>按姓名查詢:<input type="text" name="name" value="" title="姓名不能為空"></input> <input type="submit" value="查詢" /></h3> <br> </form>

42、 <form action="ageselect.jsp"method="post"> <h3> 按年齡查詢:<input type="text" name="age" value="" title="年齡不能為空"></input> <input type="submit" value="查詢"/></h3> <br> </form> &l

43、t;form action="genderselect.jsp"method="post"> <h3> 按性別查詢:<input type="text" name="gender" value=""title="性別不能為空"></input> <input type="submit" value="查詢"/></h3> <br> </form>

44、<form action="majorselect.jsp"method="post"> <h3> 按專業(yè)查詢:<input type="text" name="major" value=""title="專業(yè)不能為空"></input> <input type="submit" value="查詢"/></h3> <br> </form>

45、<br><h3><a href=submit.jsp>返回信息輸入頁面</a></h3> <br> <% if(rs!=null) rs.close(); if(stat!=null) stat.close(); if(conn!=null) conn.close(); %> </body></html>4.4 delete.jsp文件<% page language="java" import="java.util.*" pageEncod

46、ing="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4

47、.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>刪除頁面</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-

48、equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href=&

49、quot;styles.css">-> </head> <body> <% request.setCharacterEncoding("UTF-8"); String id=request.getParameter("id"); / String name=request.getParameter("name"); / String age=request.getParameter("age"); / String gender=request.getParame

50、ter("gender"); / String major=request.getParameter("major"); Connection conn=null; Statement stat=null; ResultSet rs=null; Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:localhost:1521:orcl" String user="scott" String

51、password="tiger" conn=DriverManager.getConnection(url,user,password); stat=conn.createStatement(); rs=stat.executeQuery("delete from student where id="+id+""); if(rs.next() out.print("<center><br><br><h3>刪除成功!</h3></center>"

52、); else out.print("<center><h3>刪除失敗!</h3></center>"); %> <br> <br> <center> <a href=submit.jsp>返回信息輸入頁面</a> <a href=layout.jsp>返回信息查詢頁面</a></center> <% if(rs!=null) rs.close(); if(stat!=null) stat.close(); if(con

53、n!=null) conn.close(); %> </body></html>4.5 idselect.jsp文件<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme

54、()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>按學(xué)號條件查詢</title> <meta h

55、ttp-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><

56、meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body> <% request.setCharacterEncoding("UTF-8"); String id=request.getParameter(&qu

57、ot;id"); Connection conn=null; Statement stat=null; ResultSet rs=null; Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:localhost:1521:orcl" String user="scott" String password="tiger" conn=DriverManager.getConnection(url,use

58、r,password); stat=conn.createStatement(); rs=stat.executeQuery("select * from student where id="+id+""); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <br> <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:das

59、hed 1pt"> <tr> <td>學(xué)號</td> <td>姓名</td> <td>年齡</td> <td>性別</td> <td>專業(yè)</td> </tr> <% if(rs.next() out.print("<tr>"); out.print("<td>"+rs.getInt("id")+"</td>");

60、out.print("<td>"+rs.getString("name")+"</td>"); out.print("<td>"+rs.getInt("age")+"</td>"); out.print("<td>"+rs.getString("gender")+"</td>"); out.print("<td>"

61、+rs.getString("major")+"</td>"); %> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a></td> <td><a href="update3.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.

62、print("</tr>"); else out.print("<h4>不存在此條件的信息!</h4>"); %> </table> <br> <br> <h4><a href=layout.jsp>返回查詢頁面</a></h4> <% if(rs!=null) rs.close(); if(stat!=null) stat.close(); if(conn!=null) conn.close(); %> </b

63、ody></html>4.6 nameselect.jsp<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServer

64、Name()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>按姓名查詢</title> <meta http-equiv="pragma" content=

65、"no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description&quo

66、t; content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body> <% request.setCharacterEncoding("UTF-8"); String name=request.getParameter("name"); Connection conn=nul

67、l; Statement stat=null; ResultSet rs=null; Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:localhost:1521:orcl" String user="scott" String password="tiger" conn=DriverManager.getConnection(url,user,password); stat=conn.createStat

68、ement(); rs=stat.executeQuery("select * from student where name='"+name+"'"); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <br> <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> &

69、lt;tr> <td>學(xué)號</td> <td>姓名</td> <td>年齡</td> <td>性別</td> <td>專業(yè)</td> </tr> <% if(rs.next() out.print("<tr>"); out.print("<td>"+rs.getInt("id")+"</td>"); out.print("<

70、;td>"+rs.getString("name")+"</td>"); out.print("<td>"+rs.getInt("age")+"</td>"); out.print("<td>"+rs.getString("gender")+"</td>"); out.print("<td>"+rs.getString("

71、;major")+"</td>"); %> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a></td> <td><a href="update3.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.print("</tr

72、>"); else out.print("<h4>不存在此條件的信息!</h4>"); %> </table> <br> <br> <h4><a href=layout.jsp>返回查詢頁面</a></h4> <% if(rs!=null) rs.close(); if(stat!=null) stat.close(); if(conn!=null) conn.close(); %> </body></html>

73、;4.7 ageselect.jsp文件<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/&quo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論