jsp進(jìn)行簡(jiǎn)單的增刪改查_(kāi)第1頁(yè)
jsp進(jìn)行簡(jiǎn)單的增刪改查_(kāi)第2頁(yè)
jsp進(jìn)行簡(jiǎn)單的增刪改查_(kāi)第3頁(yè)
jsp進(jìn)行簡(jiǎn)單的增刪改查_(kāi)第4頁(yè)
jsp進(jìn)行簡(jiǎn)單的增刪改查_(kāi)第5頁(yè)
已閱讀5頁(yè),還剩30頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、網(wǎng)上有教程,簡(jiǎn)單的提一下。進(jìn)入oracle官網(wǎng),找到相關(guān)的jdk,我用的是Java SE 61,點(diǎn)擊JDK 下面Download下載完成之后,可以看到是一個(gè)exe文件。2,接下來(lái)就是安裝,雙擊文件。安裝文件很簡(jiǎn)單,只要按照向?qū)б宦废乱徊骄蚈K,但是需要主要的幾個(gè)地方:安裝的路徑要改一下,默認(rèn)的是安裝在c:/program files/下面3,我們改成F盤(pán),這樣操作方便一點(diǎn)。4,安裝完成之后就是配置環(huán)境變量我安裝的JDK默認(rèn)是裝在F:/JAVA目錄下,結(jié)構(gòu)如下右擊我的電腦 >> 點(diǎn)擊環(huán)境變量:在用戶(hù)變量中新建環(huán)境變量變量名: JAVA_HOME變量值: F:JAVA變量名: clas

2、spath變量值: F:JAVAjrelibrt.jar;.;在系統(tǒng)變量中編輯path變量值最前面加上 F:JAVAbin; (一定要加上分號(hào))5,測(cè)試java是否安裝成功Windows + R 打開(kāi)cmd,確定敲 java version若出現(xiàn)java version “”則說(shuō)明安裝成功至此,JDK安裝完成二、安裝Tomcat服務(wù)器1,進(jìn)入Tomcat官網(wǎng),進(jìn)行下載下載core中的第二個(gè)即可。右擊,解壓到當(dāng)前文件夾即可這就是Tomcat的目錄結(jié)構(gòu)。若出現(xiàn)這樣的情況,那就證明你安裝成功了或者更好的辦法是進(jìn)入http:/localhost:8080/ 若顯示頁(yè)面那就證明成功了至此,JDK和Tom

3、cat都安裝完成。三、MySql安裝進(jìn)入MySql官網(wǎng)點(diǎn)擊Download,接下來(lái)選擇要下載的版本。我們點(diǎn)下面那個(gè)Download。下載完成之后進(jìn)行安裝.雙擊我們已經(jīng)下載好的msi文件。根據(jù)向?qū)нM(jìn)行安裝。一路默認(rèn)下來(lái)。但是注意:這里要選第三個(gè):且Character Set : utf-8再一路下去到這里的時(shí)候直到最后Finish就OK了。這樣就安裝完成了接下來(lái)就是要測(cè)試安裝是否成功。在開(kāi)始菜單所有程序中找到MySql啟動(dòng)程序.輸入密碼:root剛才我們?cè)O(shè)置的密碼若進(jìn)去這個(gè)頁(yè)面了,那就說(shuō)明已經(jīng)安裝成功了準(zhǔn)備工作已經(jīng)做完了。接下來(lái)就是要搭建環(huán)境了。四、創(chuàng)建數(shù)據(jù)庫(kù)mysql>create da

4、tabase jsp; mysql>use jspmysql>create table student( ->id int(30) not null primary key, ->name varchar(50), ->age int(30), ->gender varchar(30), ->major varchar(50) ->); 至此創(chuàng)建了名為jsp的數(shù)據(jù)庫(kù),一個(gè)名叫student的表.五、頁(yè)面制作pic 文件夾中放的是圖片,網(wǎng)頁(yè)要用背景圖片.自己可以到網(wǎng)上找找。不要太大的。但是名字要改成中的內(nèi)容為:<?xml version=&q

5、uot;1.0" encoding="UTF-8"?><web-app version="2.5" xmlns=" xmlns:xsi="/2001/XMLSchema-instance" <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list&g

6、t;</web-app><% page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%&

7、gt;<!DOCTYPE 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

8、" content="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=&q

9、uot;stylesheet" 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.maj

10、or.value; if(id <= 0)alert("學(xué)號(hào)不能為空,請(qǐng)輸入學(xué)號(hào)!");return false; else if(name.length <= 0)alert("姓名不能為空,請(qǐng)輸入姓名!");return false; else if(age <= 0)alert("請(qǐng)輸入合法年齡!");return false; else if(major.length <= 0)alert("專(zhuān)業(yè)不能為空,請(qǐng)輸入所學(xué)專(zhuān)業(yè)!");return false; elsereturn tru

11、e; /document.getElementById("form").submit(); </script> </head> <body background="pic/background.jpg"> <br> <center> <h2>添加學(xué)生信息</h2><hr> <form action="insert.jsp" method="post" id="form" onSubmit=&qu

12、ot;return validate()" ><h4> 學(xué)號(hào):<input type="text" name="id" class="required:true"></input><br></h4><h4> 姓名:<input type="text" name="name"></input><br></h4><h4> 年齡:<input typ

13、e="text" name="age"></input><br></h4><h4> 性別:<input type="radio" name="gender" value="男">男 <input type="radio" name="gender" value="女">女<br></h4><h4> 專(zhuān)業(yè):<input

14、type="text" name="major"></input><br></h4> <input type="submit" value="提交"/> </form> <a href="showInfo.jsp">查詢(xún)所有學(xué)生信息</a> </center> </body></html><% page language="java" impor

15、t="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE

16、 HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>刪除頁(yè)面</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content=&quo

17、t;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="stylesheet"

18、; type="text/css" href="styles.css">-> </head> <body background="pic/background.jpg"> <% request.setCharacterEncoding("UTF-8"); String id = request.getParameter("id"); Connection conn = null; Statement stat = null; ResultSet rs =

19、 null; Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" String user = "root" String password = "root" conn = DriverManager.getConnection(url,user,password); stat = conn.createStatement(); stat.executeUpdate("delete fro

20、m student where id = " + id + ""); rs = stat.executeQuery("select * from student"); if(rs.next() out.print("<center><br><br><h3>刪除成功!</h3></center>"); else out.print("<center><h3>刪除失??!</h3></center>&q

21、uot;); %> <br> <br> <center> <a href=addStuInfo.jsp>返回添加信息頁(yè)面</a> <a href=showInfo.jsp>返回信息查詢(xún)頁(yè)面</a></center> <% if(rs != null) rs.close(); rs = null; if(stat != null) stat.close(); stat = null; if(conn != null) conn.close(); conn = null; %> <

22、;/body></html><% page language="java" import="java.util.*" pageEncoding="GB18030"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/&

23、quot;%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>Welcome,home</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="ca

24、che-control" content="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"><!-<

25、link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body background="pic/background.jpg"><br/><br/><center> <a href="addStuInfo.jsp">點(diǎn)此添加學(xué)生信息</a><br/><br/> <a href="s

26、howInfo.jsp">點(diǎn)此查詢(xún)學(xué)生信息</a><br/><br/> <a href="showInfo.jsp">點(diǎn)此修改學(xué)生信息</a><br/><br/> <a href="showInfo.jsp">點(diǎn)此刪除學(xué)生信息</a><br/><br/><br></center> </body></html><% page language="j

27、ava" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%&

28、gt;<!DOCTYPE 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&q

29、uot; content="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=&quo

30、t;stylesheet" type="text/css" href="styles.css">-> </head> <body background="pic/background.jpg"> <% request.setCharacterEncoding("UTF-8"); String id = request.getParameter("id"); String name = request.getParameter("nam

31、e"); System.out.println(name); String age = request.getParameter("age"); String gender = request.getParameter("gender"); String major = request.getParameter("major"); Connection conn = null; Statement stat = null; ResultSet rs = null; Class.forName("com.mysql.

32、jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" String user = "root" String password = "root" conn = DriverManager.getConnection(url, user, password); stat = conn.createStatement(); String sql = "insert into student(id,name,age,gender,major) value

33、s(" + id + ",'" + name + "'," + age + ",'" + gender + "','" + major + "')" stat.executeUpdate(sql); rs = stat.executeQuery("select * from student"); %> <center> <% if(rs.next() out.print("<br

34、><h3>成功輸入!</h3>"); else out.print("<br><h3>輸入失??!</h3>"); %> <br> <a href=addStuInfo.jsp>返回添加信息頁(yè)面</a> <a href=showInfo.jsp>進(jìn)入信息查詢(xún)頁(yè)面</a> </center> <% if(rs != null) rs.close(); rs = null; if(stat != null) stat.cl

35、ose(); stat = null; if(conn != null) conn.close(); conn = null; %> </body></html><% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextPath();String baseP

36、ath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html> <head> <base href="<%=basePath%>"> <title>按年齡查詢(xún)<

37、/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="keywords" content="keyword1,keyword2,ke

38、yword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body background="pic/background.jpg"> <% request.setCharacterE

39、ncoding("UTF-8"); String age = request.getParameter("age"); Connection conn = null; Statement stat = null; ResultSet rs = null;Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" String user = "root" String password

40、= "root" conn = DriverManager.getConnection(url,user,password); stat = conn.createStatement(); rs = stat.executeQuery("select * from student where age=" + age + ""); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <br> <table width="450" bor

41、der="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <tr> <td>學(xué)號(hào)</td> <td>姓名</td> <td>年齡</td> <td>性別</td> <td>專(zhuān)業(yè)</td> </tr> <% while(rs.next() out.print("<tr>"); out.print(&

42、quot;<td>" + rs.getInt("id") + "</td>"); out.print("<td>" + rs.getString("name") + "</td>"); out.print("<td>" + rs.getInt("age") + "</td>"); out.print("<td>" + rs.

43、getString("gender") + "</td>"); out.print("<td>" + rs.getString("major") + "</td>"); %> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a></td> <td><a href="up

44、date.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.print("</tr>"); %> </table> <br> <br> <h4><a href=showInfo.jsp>返回查詢(xún)頁(yè)面</a></h4> <% if(rs != null) rs.close(); rs = null; if(stat != null) stat.c

45、lose(); stat = null; if(conn != null) conn.close(); conn = null; %> </body></html>select_for_gender<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String path = request.getContextP

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

47、title>按性別查詢(xún)</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="keywords" content="ke

48、yword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body background="pic/background.jpg"> <% req

49、uest.setCharacterEncoding("UTF-8"); String gender = request.getParameter("gender"); Connection conn = null; Statement stat = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" String user = "ro

50、ot" String password = "root" conn = DriverManager.getConnection(url,user,password); stat = conn.createStatement(); rs = stat.executeQuery("select * from student where gender='" + gender + "'"); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <b

51、r> <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <tr> <td>學(xué)號(hào)</td> <td>姓名</td> <td>年齡</td> <td>性別</td> <td>專(zhuān)業(yè)</td> </tr> <% while(rs.next() out.p

52、rint("<tr>"); out.print("<td>" + rs.getInt("id") + "</td>"); out.print("<td>" + rs.getString("name") + "</td>"); out.print("<td>" + rs.getInt("age") + "</td>"

53、); out.print("<td>" + rs.getString("gender") + "</td>"); out.print("<td>" + rs.getString("major") + "</td>"); %> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a>

54、</td> <td><a href="update.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.print("</tr>"); %> </table> <br> <br> <h4><a href=showInfo.jsp>返回查詢(xún)頁(yè)面</a></h4> <% if(rs != null) rs.cl

55、ose(); rs = null; if(stat != null) stat.close(); stat = null; if(conn != null) conn.close(); conn = null; %> </body></html><% page language="java" import="java.util.*" pageEncoding="UTF-8"%><% page import="java.sql.*"%><%String pa

56、th = 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="<%=base

57、Path%>"> <title>按學(xué)號(hào)條件查詢(xún)</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="keywo

58、rds" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!-<link rel="stylesheet" type="text/css" href="styles.css">-> </head> <body background="pic/backgrou

59、nd.jpg"> <% request.setCharacterEncoding("UTF-8"); String id = request.getParameter("id"); Connection conn = null; Statement stat = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" Stri

60、ng user = "root" String password = "root" conn = DriverManager.getConnection(url,user,password); stat = conn.createStatement(); rs = stat.executeQuery("select * from student where id=" + id + ""); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <b

61、r> <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <tr> <td>學(xué)號(hào)</td> <td>姓名</td> <td>年齡</td> <td>性別</td> <td>專(zhuān)業(yè)</td> </tr> <% if(rs.next() out.prin

62、t("<tr>"); out.print("<td>" + rs.getInt("id") + "</td>"); out.print("<td>" + rs.getString("name") + "</td>"); out.print("<td>" + rs.getInt("age") + "</td>");

63、out.print("<td>" + rs.getString("gender") + "</td>"); out.print("<td>" + rs.getString("major") + "</td>"); %> <td><a href="delete.jsp?id=<%=rs.getInt("id") %>">刪除</a><

64、;/td> <td><a href="update.jsp?id=<%=rs.getInt("id") %>">修改</a></td> <% out.print("</tr>"); else out.print("<h4>不存在此條件的信息!</h4>"); %> </table> <br> <br> <h4><a href=showInfo.jsp

65、>返回查詢(xún)頁(yè)面</a></h4> <% if(rs != null) rs.close(); rs = null; if(stat != null) stat.close(); stat = null; if(conn != null) conn.close(); conn = null; %> </body></html><% page language="java" import="java.util.*" pageEncoding="UTF-8"%>&

66、lt;% 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"&g

67、t;<html> <head> <base href="<%=basePath%>"> <title>按專(zhuān)業(yè)查詢(xún)</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" c

68、ontent="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">-&

69、gt; </head> <body background="pic/background.jpg"> <% request.setCharacterEncoding("UTF-8"); / String id=request.getParameter("id"); / String name=request.getParameter("name"); / String age=request.getParameter("age"); / String gender=

70、request.getParameter("gender"); String major=request.getParameter("major"); /major=; Connection conn = null; Statement stat = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql:/localhost:3306/jsp" String user = "r

71、oot" String password = "root" conn = DriverManager.getConnection(url,user,password); stat = conn.createStatement(); rs = stat.executeQuery("select * from student where major='" + major + "'"); %> <br> <h3>符合條件的學(xué)生信息</h3><hr> <br> &

溫馨提示

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

評(píng)論

0/150

提交評(píng)論