1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      如何制作一個JSP留言板

      這篇文章主要介紹如何制作一個JSP留言板,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

      創(chuàng)新互聯(lián)是一家專業(yè)提供咸陽企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計制作、做網(wǎng)站、H5網(wǎng)站設(shè)計、小程序制作等業(yè)務(wù)。10年已為咸陽眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進行中。

      一.JSP留言板:創(chuàng)建數(shù)據(jù)庫

      1).打開Access2000,創(chuàng)建一個新的數(shù)據(jù)庫,我將這個數(shù)據(jù)庫命名為foxdb.mdb,存在C:\tomcat\fox\global\foxdb.mdb。接下來在 eagle.mdb中創(chuàng)建一個表,命名為foxtable,表中有五個字段,全為文本格式:

      其中“URL”用于記錄留言者的 IP 。至于各字段的長度,我把“留言”定為200,其它四個各為20。

      2).指定ODBC數(shù)據(jù)源,其名為foxdb ,指向 C:\tomcat\fox\global\foxdb.mdb。

      二.JSP留言板:編寫用戶的留言界面

      foxnote.html,存于C:\tomcat\fox\foxnote.html:

      ﹤html﹥  ﹤body﹥  ﹤form method="post" action="foxnoteinsert.jsp"﹥   ﹤br﹥姓名:   ﹤input name=username size=15value=""﹥  ﹤br﹥郵箱:   ﹤input name=email size=15value=""﹥   ﹤br﹥留言:   ﹤br﹥  ﹤textarea name=doc rows="5" cols="40"﹥  ﹤/textarea﹥   ﹤br﹥   ﹤input type=submit value="遞交"﹥   ﹤input type=reset value="重填"﹥   ﹤/form﹥   ﹤/bocy﹥  ﹤/html﹥

      在IE中鍵入 http://ip/fox/foxnote.html 看看是否顯示正常(ip是你機器的ip地址)

      三.JSP留言板:編寫 foxnoteinsert.jsp

      將用戶的留言寫進數(shù)據(jù)庫表中:

      ﹤body bgcolor="#FFFFFF"﹥  ﹤%@ page import="java.sql.*,MyUtil,java.util.*"%﹥   ﹤%  Connection con=null;   String username=MyUtil.gb2312ToUnicode(request.getParameter("username"));   String email=MyUtil.gb2312ToUnicode(request.getParameter("email"));   String doc=MyUtil.gb2312ToUnicode(request.getParameter("doc"));   String url=request.getRemoteAddr();   try {   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbcdbc:foxdb","","");   String str="insert into foxtable values(?,?,?,?);";   PreparedStatement pstmt=con.prepareStatement(str);   pstmt.setString(1,username);  pstmt.setString(2,email);  pstmt.setString(3,doc);   pstmt.setString(4,url);   pstmt.executeUpdate();   pstmt.close();  con.close();  }   catch(Exception e) {   out.println(e.getMessage());   }  %﹥

      這個程序中有一些要說明的地方,就是其中用到了一個 JavaBean :MyUtil.class 。

      MyUtil 的作用是字符串之間的轉(zhuǎn)換。必需關(guān)注的是JSP的字符串以Unicode碼表示,而留言板界面的表單卻是以 gb2312碼表示。所以將用戶的留言寫進數(shù)據(jù)庫還需要碼間的轉(zhuǎn)換。如果不轉(zhuǎn)換而把留言直接寫到數(shù)據(jù)庫表,則會產(chǎn)生亂碼。下面是 MyUtil的原代碼,存于C:\tomcat\fox\WEB-INF\classes\MyUtil.java,編譯后的MyUtil.class文件也存于此。

      import java.io.*;   public class MyUtil{  public static String gb2312ToUnicode(String s){  try{  return new String(s.getBytes("ISO8859_1"),"gb2312");   }   catch(UnsupportedEncodingException uee){  return s;  }   }  public static String unicodeTogb2312(String s){  try{  return new String(s.getBytes("gb2312"),"ISO8859_1");  }   catch(UnsupportedEncodingException uee){  return s;  }  }  }

      四.JSP留言板:編寫 foxnoteview.jsp

      用于瀏覽數(shù)據(jù)庫表中已有的留言,存于C:\tomcat\fox\foxnoteview.jsp ,代碼如下:

      ﹤html﹥  ﹤body﹥   ﹤%@ page c language="java" import="java.sql.*"%﹥  ﹤%  Connection con=null;  try  {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  con=DriverManager.getConnection("jdbcdbc:foxdb","","");  Statement statement=con.createStatement();  ResultSet rs=statement.executeQuery("select * from foxtable");   %﹥   ﹤table border="1" width="100%" cellspacing="0" cellpadding="0"align="center" bordercolorlight="#CCCCFF" bordercolordark="#FFFFFF"﹥  ﹤tr bgcolor="#FFFFFF"﹥   ﹤td width="15%" height="25" align="center"﹥﹤i﹥作者﹤/i﹥﹤/td﹥  ﹤td width="28%" height="25" align="center"﹥﹤i﹥發(fā)表時間﹤/i﹥﹤/td﹥  ﹤td width="22%" height="25" align="center"﹥﹤i﹥Email﹤/i﹥﹤/td﹥  ﹤td width="35%" height="25" align="center"﹥﹤i﹥留言內(nèi)容﹤/i﹥﹤/td﹥  ﹤%  while(rs.next()){  out.println("﹤TR﹥﹤td align=center﹥﹤font size=2color=#999999﹥"+rs.getString("作者")+"﹤/TD﹥");  out.println("﹤TD﹥﹤font size=2color=#999999﹥"+rs.getString("Email")+"﹤/font﹥﹤/TD﹥");  out.println("﹤TD﹥﹤font size=2color=#999999﹥"+rs.getString("留言")+"﹤/font﹥﹤/TD﹥");  out.println("﹤TD﹥﹤font size=2color=#999999﹥"+rs.getString("URL")+"﹤/font﹥﹤/TD﹥﹤/TR﹥");  }  rs.close();  con.close();  }  catch(Exception e)  {  out.println(e.getMessage());  }  %﹥   ﹤/table﹥  ﹤/body﹥  ﹤/html﹥

      以上是“如何制作一個JSP留言板”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


      分享文章:如何制作一個JSP留言板
      文章網(wǎng)址:http://www.ef60e0e.cn/article/gjpdip.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        敖汉旗| 科技| 巴东县| 四子王旗| 济宁市| 独山县| 应用必备| 南江县| 余姚市| 怀柔区| 高邑县| 闻喜县| 富源县| 陕西省| 临桂县| 昂仁县| 彭阳县| 永靖县| 龙泉市| 车致| 开平市| 牟定县| 望谟县| 临泉县| 图木舒克市| 额敏县| 施甸县| 苗栗市| 边坝县| 和政县| 连州市| 安化县| 昆山市| 广河县| 霍山县| 四会市| 万山特区| 定州市| 扶绥县| 河北省| 连云港市|