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
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網營銷解決方案
      JSP如何配置數(shù)據(jù)庫

      這篇文章將為大家詳細講解有關JSP如何配置數(shù)據(jù)庫,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

      10多年的子長網站建設經驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。成都全網營銷推廣的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調整子長建站的顯示方式,使網站能夠適用不同顯示終端,在瀏覽器中調整網站的寬度,無論在任何一種瀏覽器上瀏覽網站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“子長網站設計”,“子長網站推廣”以來,每個客戶項目都認真落實執(zhí)行。

      JSP數(shù)據(jù)庫配置步驟三

      在項目下新建包beans,在此包下編寫一個JavaBean程序,命名為Test_2_4.java,代碼為:

      package import java.io.UnsupportedEncodingException;  import java.sql.*;  import java.util.ResourceBundle;  public class Test_2_4 {      private String username;      private String password;      private Connection conn = null;      private PreparedStatement ps = null;      private ResultSet rs = null;      public String getUsername() {          return username;      }      public void setUsername(String username)              throws UnsupportedEncodingException {          String temp = new String(username.getBytes("iso8859-1"), "utf-8");          this.username = temp;      }      public String getPassword() {          return password;      }      public void setPassword(String password) {          this.password = password;      }      private void closeConn() {          /**          * 關閉數(shù)據(jù)連接的方法          * */         try {              ps.close();          } catch (SQLException e) {              e.printStackTrace();          }          ps = null;          try {              rs.close();          } catch (SQLException e) {              e.printStackTrace();          }          rs = null;          if (conn != null)              try {                  conn.close();              } catch (SQLException e) {                  e.printStackTrace();              }          conn = null;      }         public int query() {          int tag = 0;          if (username == null || password == null) {              return 0;          }          ResourceBundle rb = ResourceBundle.getBundle("init");          String dbDirver = rb.getString("connJDBC.dbDriver");          String dbUrl = rb.getString("connJDBC.dbURL");          String dbUsername = rb.getString("connJDBC.dbUsername");          String dbPwd = rb.getString("connJDBC.dbPassword");          try {              Class.forName(dbDirver);              conn = DriverManager.getConnection(dbUrl, dbUsername, dbPwd);              String sql = "select * from users where username=? and password=?";              ps = conn.prepareStatement(sql);              ps.setString(1, username);              ps.setString(2, password);              rs = ps.executeQuery();              if (rs.next()) {                  return 1;              } else {                  return -1;              }          } catch (SQLException e) {              e.printStackTrace();          } catch (ClassNotFoundException e) {              e.printStackTrace();          }          /**          * 調用關閉數(shù)據(jù)連接的方法,關閉數(shù)據(jù)庫連接          * */         closeConn();          return tag;      }  }

      JSP數(shù)據(jù)庫配置步驟四

      新建jsp文件,命名為test_2_4.jsp,代碼如下:

      < %@ page language="java" contentType="text/html; charset=UTF-8"     pageEncoding="UTF-8"%> < jsp:useBean id="login" class="beans.Test_2_4" scope="session" /> < jsp:setProperty name="login" property="*" /> < !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html> < head> < meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> < title>實驗二利用JavaBean實現(xiàn)用戶登錄< /title> < /head> < body> < form action="test_2_3.jsp" method="post"> < div align="center">用戶名< input type="text" name="username"     size="16">< /div> < div align="center">密    碼< input     type="password" name="password" size="16">< /div> < div align="center">< input type="submit" value="登錄">      < input     type="reset" value="重置">< /div> < /form> < %      request.setCharacterEncoding("utf-8");      int isLogin = login.query();      if (isLogin == 1) {          String username = request.getParameter("username");          session.putValue("username", username);          response.sendRedirect("welcome.jsp");      } else if (isLogin == -1) {          out.println("< script language=javascript>alert('登錄失??!您沒有權限訪問!');< /script");      }  %> < /body> < /html>

      JSP數(shù)據(jù)庫配置步驟五

      創(chuàng)建以歡迎登錄成功的頁面welcome.jsp,代碼如下:

      < %@ page language="java" contentType="text/html; charset=UTF-8"      pageEncoding="UTF-8"%> < !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html> < head> < meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> < title>登錄成功< /title> < /head> < body> < %       request.setCharacterEncoding("utf-8");       if (session.getValue("username") == ""                || session.getValue("username") == null) {           response.sendRedirect("test_2_4.jsp");       } else {           String username = session.getValue("username").toString();           String user = new String(username.getBytes("iso8859-1"),                     "utf-8");  %> < %=user%>,歡迎您訪問!  < %       }  %> < /body> < /html>

      JSP數(shù)據(jù)庫配置步驟六

      測試效果,如下:

      ①未進行登錄操作:

      JSP如何配置數(shù)據(jù)庫

      ②登錄成功

      JSP如何配置數(shù)據(jù)庫

      JSP如何配置數(shù)據(jù)庫

      ③登錄失敗

      JSP如何配置數(shù)據(jù)庫

      關于“JSP如何配置數(shù)據(jù)庫”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。


      標題名稱:JSP如何配置數(shù)據(jù)庫
      文章地址:http://ef60e0e.cn/article/podcgi.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>

        小金县| 威宁| 新巴尔虎右旗| 文昌市| 莱州市| 冕宁县| 绥芬河市| 阿拉善右旗| 合山市| 富阳市| 错那县| 莱芜市| 九寨沟县| 元阳县| 景谷| 溧阳市| 筠连县| 陇川县| 苗栗县| 丹江口市| 进贤县| 怀柔区| 调兵山市| 色达县| 开江县| 云林县| 鄂伦春自治旗| 三明市| 内江市| 西安市| 临西县| 凤山县| 宿迁市| 都江堰市| 汝南县| 孝感市| 永川市| 普安县| 平潭县| 五河县| 固原市|