a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > JSP > 正文

JSP簡單添加,查詢功能代碼

2024-09-05 00:22:22
字體:
供稿:網(wǎng)友

這篇文章主要介紹了JSP簡單添加,查詢功能代碼,以實(shí)例形式分析了JSP實(shí)現(xiàn)簡單添加及查詢功能的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JSP簡單添加,查詢功能。分享給大家供大家參考。具體如下:

JSP技術(shù):

 

 
  1. public class ISOtoGb2312 
  2. public static String convert( String str ) 
  3. try 
  4. byte<> bytesStr=str.getBytes( "ISO-8859-1" ) ; 
  5. return new String( bytesStr, "gb2312" ) ;  
  6. catch( Exception ex) 
  7. return str ; 

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. 輸入數(shù)據(jù) 
  6. </title> 
  7. </head> 
  8. <body bgcolor="#ffffff"
  9. <h1> 
  10. 請輸入數(shù)據(jù): 
  11. </h1> 
  12. <hr> 
  13. <form method="POST" action="insert.jsp"
  14. <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt" 
  15. S-Format="TEXT/CSV" S-Label-Fields="TRUE" --> 
  16. <p> </p> 
  17. <p> </p> 
  18. <p><img border="0" src="img/cisco.gif" width="70" height="81"
  19. <font size="5" color="#0000FF"><b>學(xué) 號: 
  20. </b></font><input type="text" name="id" size="25"> <img border="0" src="img/cisco.gif" width="70" height="81"
  21. <font size="5" color="#0000FF"><b>性 別</b></font><font size="5" color="#0000FF"><b>: 
  22. </b></font><input type="text" name="sex" size="24"></p> 
  23. <p><img border="0" src="img/cisco.gif" width="70" height="81"
  24. <font size="5" color="#000080"><b>姓 名: 
  25. </b></font><input type="text" name="name" size="25"> <img border="0" src="img/cisco.gif" width="70" height="81"
  26. <font size="5" color="#0000FF"><b>年 齡: </b></font><input type="text" name="age" size="24"></p> 
  27. <p><img border="0" src="img/cisco.gif" width="70" height="81"
  28. <font size="5" color="#000080"><b>地 址: 
  29. </b></font><input type="text" name="addr" size="84"> </p> 
  30. <p> </p> 
  31. <p> 
  32. <input type="submit" value="提交" name="B1" style="font-size: 14pt; font-weight: bold"
  33. <input type="reset" value="全部重寫" name="B2" style="font-size: 14pt; font-weight: bold"
  34. </p> 
  35. </form> 
  36. </body> 
  37. </html> 

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <%@ page import = "java.sql.*"%> 
  3. <%@ page language = "java"%> 
  4. <%@ page import = "test.ISOtoGb2312"%> 
  5. <html> 
  6. <head> 
  7. <title> 
  8. 添加數(shù)據(jù) 
  9. </title> 
  10. </head> 
  11. <body bgcolor="#ffffff"
  12. <h1> 
  13. 接收數(shù)據(jù),添加到數(shù)據(jù)庫. 
  14. </h1> 
  15. <% 
  16. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //載入驅(qū)動程序類別 
  17. Connection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立數(shù)據(jù)庫鏈接 
  18. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
  19. ResultSet.CONCUR_READ_ONLY); 
  20. String strSQL; 
  21. strSQL = "INSERT INTO tab02(id, name, sex, " + 
  22. "age, addr) Values (" + 
  23. ISOtoGb2312.convert( request.getParameter("id")) + "," + 
  24. ISOtoGb2312.convert( request.getParameter("name")) + "," + 
  25. ISOtoGb2312.convert( request.getParameter("sex")) + "," + 
  26. ISOtoGb2312.convert( request.getParameter("age")) + "," + 
  27. ISOtoGb2312.convert( request.getParameter("addr")) + ")"
  28. stmt.executeUpdate(strSQL); 
  29. ResultSet rs; //建立ResultSet(結(jié)果集)對象 
  30. rs = stmt.executeQuery("SELECT * FROM tab02"); //執(zhí)行SQL語句 
  31. %> 
  32. <CENTER> 
  33. <TABLE bgcolor=pink> 
  34. <TR bgcolor=silver> 
  35. <TD><B>編號</B></TD><TD><B>姓 名 </B></TD><TD><B>性 別</B></TD><TD><B> 年 齡</B></TD><TD><B>地 址</B></TD> 
  36. </TR> 
  37. <% 
  38. //利用while循環(huán)將數(shù)據(jù)表中的記錄列出 
  39. while (rs.next()) 
  40. %> 
  41. <TR bgcolor=white> 
  42. <TD><B><%= rs.getString("id") %></B></TD> 
  43. <TD><B><%= rs.getString("name") %></B></TD> 
  44. <TD><B><%= rs.getString("sex") %></B></TD> 
  45. <TD><B><%= rs.getString("age") %></B></TD> 
  46. <TD><B><%= rs.getString("addr") %></B></TD> 
  47. </TR> 
  48. <% 
  49. rs.close(); //關(guān)閉ResultSet對象 
  50. stmt.close(); //關(guān)閉Statement對象 
  51. con.close(); //關(guān)閉Connection對象 
  52. %> 
  53. </TABLE> 
  54. </CENTER> 
  55. <h3><a href="jsp1.jsp">返回</a></h3> 
  56. </body> 
  57. </html> 

jsp1:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <%@ page import="com.borland.internetbeans.*,com.borland.dx.dataset.*,com.borland.dx.sql.dataset.*" %> 
  3. <%@ taglib uri="/internetbeans.tld" prefix="ix" %> 
  4. <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %> 
  5. <html> 
  6. <head> 
  7. <title> 
  8. jsp1 
  9. </title> 
  10. </head> 
  11. <jsp:useBean id="jsp1BeanId" scope="session" class="test.Jsp1Bean" /> 
  12. <jsp:setProperty name="jsp1BeanId" property="*" /> 
  13. <body bgcolor="#ff00ff"
  14. <h1> 
  15. JBuilder Generated JSP 
  16. <br> 
  17. <hr> 
  18. 這是第一次使用JSP技術(shù) !!!----2004/3/1--南昌大學(xué)軟件學(xué)院---- 
  19. </h1> 
  20. <h3><a href="tmp/page_1.htm">另一頁</a></h3> 
  21. <br> 
  22. <h3><a href="jsp2.jsp">下一頁</a></h3> 
  23. <br> 
  24. <h3><a href="DBBean.jsp">數(shù)據(jù)庫</a></h3> 
  25. <form method="post"
  26. <br>Enter new value : <input name="sample"><br> 
  27. <br> 
  28. <input type="submit" name="Submit" value="Submit"
  29. <input type="reset" value="Reset"
  30. <br> 
  31. Value of Bean property is :<jsp:getProperty name="jsp1BeanId" property="sample" /> 
  32. </form> 
  33. <h3><a href="jsp4.jsp">登錄</a></h3> 
  34. </body> 
  35. </html> 

Jsp1Bean.java

 

 
  1. package test; 
  2. /*aaaaaaa 
  3. bbbbbbb 
  4. ccccccccc*/ 
  5. /** 
  6. * <p>Title: </p> 
  7. * <p>Description: </p> 
  8. * <p>Copyright: Copyright (c) 2004</p> 
  9. * <p>Company: </p> 
  10. * @author not attributable 
  11. * @version 1.0 
  12. */ 
  13. public class Jsp1Bean { 
  14. private String sample = "Start value"
  15. //Access sample property 
  16. public String getSample() { 
  17. return sample; 
  18. //Access sample property 
  19. public void setSample(String newValue) { 
  20. if (newValue!=null) { 
  21. sample = newValue; 

jsp2:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <%@ page import="java.sql.*" %> 
  3. <%@ page language="java" %> 
  4. <HTML> 
  5. <HEAD> 
  6. <TITLE>順序取得數(shù)據(jù)</TITLE> 
  7. </HEAD> 
  8. <BODY> 
  9. <CENTER> 
  10. <FONT SIZE = 5 COLOR = blue>順序取得數(shù)據(jù)</FONT> 
  11. </CENTER> 
  12. <BR> 
  13. <HR> 
  14. <BR> 
  15. <CENTER> 
  16. <% 
  17. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //載入驅(qū)動程序類別 
  18. Connection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立數(shù)據(jù)庫鏈接 
  19. Statement stmt = con.createStatement(); //建立Statement對象 
  20. ResultSet rs; //建立ResultSet(結(jié)果集)對象 
  21. rs = stmt.executeQuery("SELECT * FROM tab01"); //執(zhí)行SQL語句 
  22. %> 
  23. <TABLE bgcolor=pink> 
  24. <TR bgcolor=silver> 
  25. <TD><B>學(xué) 號</B></TD><TD><B>姓 名 </B></TD><TD><B>性 別 </B></TD><TD><B>年 齡 </B></TD><TD><B>地 址</B></TD> 
  26. </TR> 
  27. <% 
  28. //利用while循環(huán)將數(shù)據(jù)表中的記錄列出 
  29. while (rs.next()) 
  30. %> 
  31. <TR bgcolor=white> 
  32. <TD><B><%= rs.getString("id") %></B></TD> 
  33. <TD><B><%= rs.getString("name") %></B></TD> 
  34. <TD><B><%= rs.getString("sex") %></B></TD> 
  35. <TD><B><%= rs.getString("age") %></B></TD> 
  36. <TD><B><%= rs.getString("addr") %></B></TD> 
  37. </TR> 
  38. <% 
  39. rs.close(); //關(guān)閉ResultSet對象 
  40. stmt.close(); //關(guān)閉Statement對象 
  41. con.close(); //關(guān)閉Connection對象 
  42. %> 
  43. </TABLE> 
  44. </CENTER> 
  45. </BODY> 
  46. </HTML> 

jsp3:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. jsp3 
  6. </title> 
  7. </head> 
  8. <jsp:useBean id="jsp3BeanId" scope="session" class="test.Jsp3Bean" /> 
  9. <jsp:setProperty name="jsp3BeanId" property="*" /> 
  10. <body bgcolor="#ffffc0"
  11. <h1> 
  12. JBuilder Generated JSP 
  13. </h1> 
  14. <form method="post"
  15. <br>Enter new value : <input name="sample"><br> 
  16. <br><br> 
  17. <input type="submit" name="Submit" value="Submit"
  18. <input type="reset" value="Reset"
  19. <br> 
  20. Value of Bean property is :<jsp:getProperty name="jsp3BeanId" property="sample" /> 
  21. </form> 
  22. </body> 
  23. </html> 

jsp4:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. 登錄 
  6. </title> 
  7. </head> 
  8. <body bgcolor="#ffffc0"
  9. <form method="POST" action="jsp6.jsp"
  10. <p align="center"
  11. 用戶名:<input type="text" name="username" size="20"></p> 
  12. <p align="center"
  13. 密 碼:<input type="password" name="password" size="20"></p> 
  14. <p align="center"
  15. <input type="radio" value="manage" checked name="select"
  16. 管理  
  17. <input type="radio" name="select" value="statistic">統(tǒng)計(jì)</p> 
  18. <p align="center"><input type="submit" value="登 錄" name="login"
  19. <input type="reset" value="重 寫" name="reset"></p> 
  20. </form> 
  21. </body> 
  22. </html> 

jsp6:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. 接收數(shù)據(jù) 
  6. </title> 
  7. </head> 
  8. <body bgcolor="#ffffff"
  9. <% 
  10. String user,pwd,choice; 
  11. user=request.getParameter("username"); 
  12. pwd=request.getParameter("password"); 
  13. choice=request.getParameter("select"); 
  14. if(choice.equals("manage")){ 
  15. //user select manage. 
  16. %> 
  17. <jsp:forward page="jsp7.jsp"
  18. <jsp:param name="username" value="<%=user%>"/> 
  19. <jsp:param name="password" value="<%=pwd%>"/> 
  20. </jsp:forward> 
  21. <% 
  22. }else
  23. //user select statistic 
  24. %> 
  25. <jsp:forward page="jsp8.jsp"
  26. <jsp:param name="username" value="<%=user%>"/> 
  27. <jsp:param name="password" value="<%=pwd%>"/> 
  28. </jsp:forward> 
  29. <% 
  30. %> 
  31. </body> 
  32. </html> 

jsp7:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. jsp7 
  6. </title> 
  7. </head> 
  8. <body bgcolor="#ffffff"
  9. <h1> 
  10. 這是管理頁 !!! 
  11. </h1> 
  12. <br> 
  13. <% 
  14. String user,pwd; 
  15. user=request.getParameter("username"); 
  16. pwd=request.getParameter("password"); 
  17. %> 
  18. username is: <%=user%><br> 
  19. password is: <%=pwd%><br> 
  20. </body> 
  21. </html> 

jsp8:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <html> 
  3. <head> 
  4. <title> 
  5. jsp8 
  6. </title> 
  7. </head> 
  8. <body bgcolor="#ffffff"
  9. <h1> 
  10. 這是統(tǒng)計(jì)頁 !!! 
  11. </h1> 
  12. <br> 
  13. <% 
  14. String user,pwd; 
  15. //user=request.getParameter("username"); 
  16. user=new String(request.getParameter("username").getBytes("ISO8859_1")); 
  17. pwd=request.getParameter("password"); 
  18. %> 
  19. username is: <%=user%><br> 
  20. password is: <%=pwd%><br> 
  21. </body> 
  22. </html> 

input.html

 

 
  1. <HTML> 
  2. <HEAD> 
  3. <TITLE>網(wǎng)頁引導(dǎo)</TITLE> 
  4. </HEAD> 
  5. <BODY> 
  6. <CENTER> 
  7. <FONT SIZE = 5 COLOR = blue>網(wǎng)頁引導(dǎo)</FONT> 
  8. </CENTER> 
  9. <BR> 
  10. <HR> 
  11. <BR> 
  12. <FORM action="sendRedirect.jsp" method=post name=form1> 
  13. <P>姓名 : <INPUT name=inputName ></P> 
  14. <P>E-Mail : <INPUT name=inputE_Mail ></P> 
  15. <INPUT name=submit type=submit value=送出> 
  16. </FORM> 
  17. </BODY> 
  18. </HTML> 

sendRedirect.jsp:

 

 
  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <%@ page language="java" %> 
  3. <% 
  4. String Name = request.getParameter("inputName"); 
  5. String E_Mail = request.getParameter("inputE_Mail"); 
  6. if(Name.equals("") || E_Mail.equals(""))//檢查Name或E_Mail是否完成資料輸入 
  7. response.sendRedirect("sendRedirect.html"); //若未完成資料輸入則將網(wǎng)頁導(dǎo)向sendRedirect.html 
  8. %> 
  9. <HTML> 
  10. <HEAD> 
  11. <TITLE>網(wǎng)頁引導(dǎo)</TITLE> 
  12. </HEAD> 
  13. <BODY> 
  14. <CENTER> 
  15. <FONT SIZE = 5 COLOR = blue>網(wǎng)頁引導(dǎo)</FONT> 
  16. </CENTER> 
  17. <BR> 
  18. <HR> 
  19. <BR> 
  20. <P>您的大名是: 
  21. <%= Name %> 
  22. </P> 
  23. <P>E-Mail帳號為: 
  24. <%= E_Mail %> 
  25. </P> 
  26. <p><a href="../jsp1.jsp">返回</a></p> 
  27. </BODY> 
  28. </HTML> 

sendRedirect.html:

 

 
  1. <HTML> 
  2. <HEAD> 
  3. <TITLE>網(wǎng)頁引導(dǎo)</TITLE> 
  4. </HEAD> 
  5. <BODY> 
  6. <CENTER> 
  7. <FONT SIZE = 5 COLOR = blue>網(wǎng)頁引導(dǎo)</FONT> 
  8. </CENTER> 
  9. <BR> 
  10. <HR> 
  11. <BR> 
  12. <FORM action="sendRedirect.jsp" method=post name=form1> 
  13. <font size=5 color=red> 
  14. 你輸入的信息不完整,請重新輸入! 
  15. </font> 
  16. <br> 
  17. <P>姓名 : <INPUT name=inputName ></P> 
  18. <P>E-Mail : <INPUT name=inputE_Mail ></P> 
  19. <INPUT name=submit type=submit value=送出> 
  20. </FORM> 
  21. </BODY> 
  22. </HTML> 

希望本文所述對大家的JSP程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 伊人yinren22综合开心 | 欧美与黑人午夜性猛交久久久 | 国产美女黄色片 | 精品久久中文字幕 | 国产精品中文字幕在线观看 | 国产精品久久久久久久久福交 | 污视频网站在线看 | 精品一区不卡 | 一区不卡| 国产精品一区二区四区 | 性色在线视频 | 琪琪av在线| 蜜臀久久99精品久久久久久宅男 | 日韩性网站 | 99视频免费 | 亚洲区在线 | 亚洲欧美精品 | 涩涩片影院 | 免费视频成人 | 国产精品毛片一区二区在线看 | 亚洲精品国产第一综合99久久 | 久久99国产精品久久99大师 | 日夜夜精品 | 久久毛片 | 欧美在线一区二区三区 | 中文字幕av亚洲精品一部二部 | www.亚洲| 久久精品视频网 | 日本不卡高字幕在线2019 | 国产日韩精品在线 | 精品999 | 亚洲精品一区二区三区麻豆 | av在线播放观看 | 在线观看亚洲免费 | 久久精品在线 | 日本特黄 | 欧美视频一区 | 日韩成人在线观看 | 成人99 | 视频一区二区中文字幕日韩 | 国产成人精品一区二区在线 |