qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          JSP網頁防止sql注入攻擊

            SQL注入攻擊指的是通過構建特殊的輸入作為參數傳入Web應用程序,而這些輸入大都是SQL語法里的一些組合,通過執行SQL語句進而執行攻擊者所要的操作,其主要原因是程序沒有細致地過濾用戶輸入的數據,致使非法數據侵入系統。
            prepareStatement方法是防止sql注入的簡單有效手段
            preparedStatement和statement的區別
            1、preparedStatement是statement的子方法
            2、preparedStatement可以防止sql注入的問題
            3、preparedStatement它可以對它所代表的sql語句進行預編譯,以減輕服務器壓力
            實例如下 
          public User find(String username, String password) {
          Connection conn = null;
          PreparedStatement st = null;
          ResultSet rs = null;
          try{
          conn = JdbcUtils.getConnection();
          String sql = "select * from users where username=? and password=?";
          st = conn.prepareStatement(sql);
          st.setString(1, username);
          st.setString(2, password);
          rs = st.executeQuery(); //
          if(rs.next()){
          User user = new User();
          user.setId(rs.getString("id"));
          user.setUsername(rs.getString("username"));
          user.setPassword(rs.getString("password"));
          user.setEmail(rs.getString("email"));
          user.setBirthday(rs.getDate("birthday"));
          return user;
          }
          return null;
          }catch (Exception e) {
          throw new DaoException(e);
          }finally{
          JdbcUtils.release(conn, st, rs);
          }

          posted on 2014-06-03 09:58 順其自然EVO 閱讀(415) 評論(1)  編輯  收藏

          評論

          # re: JSP網頁防止sql注入攻擊 2014-06-04 09:44 IT前線

          就是最基本的防注入呀,標題加了jsp,還以為是什么妖孽程序呢
          http://www.itqx.net  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2014年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乐东| 中山市| 清新县| 南汇区| 金门县| 疏附县| 安图县| 紫云| 恩施市| 南溪县| 昌江| 靖远县| 旅游| 呼伦贝尔市| 唐海县| 太仓市| 康平县| 盐城市| 南阳市| 登封市| 资源县| 夏津县| 吐鲁番市| 彰化县| 汾西县| 盖州市| 麻栗坡县| 宜章县| 宿州市| 巴塘县| 新巴尔虎左旗| 桂平市| 宣武区| 图们市| 西平县| 武鸣县| 晋宁县| 无极县| 朝阳区| 阿瓦提县| 河北区|