码迷,mamicode.com
首页 > 其他好文 > 详细

新闻发布系统

时间:2016-07-01 18:26:52      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 

function check(){
        var login_username = document.getElementById("uname");
        var login_password = document.getElementById("upwd");
        if(login_username.value == ""){
            alert("用户名不能为空!请重新填入!");
            login_username.focus();    
            return false;
        }else if(login_password.value == ""){
            alert("密码不能为空!请重新填入!");
            login_password.focus();
            return false;
        }
        return true;
    }
    
    function focusOnLogin(){
        var login_username = document.getElementById("uname");
        login_username.focus();    
    }
</script>
</head>
<body onload="focusOnLogin()">
<div id="header">
  <div id="top_login">
    <form action="util/do_login.jsp" method="post" onsubmit="return check()">
      <label> 登录名 </label>
      <input type="text" name="uname" value="" class="login_input" />
      <label> 密&#160;&#160;码 </label>
      <input type="password" name="upwd" value="" class="login_input" />
      <input type="submit" class="login_sub" value="登录" />
      <label id="error"> </label>
      <img src="images/friend_logo.gif" alt="Google" id="friend_logo" />
    </form>
  </div>
  <div id="nav">
    <div id="logo"> <img src="images/logo.jpg" alt="新闻中国" /> </div>
    <div id="a_b01"> <img src="images/a_b01.gif"  /> </div>
    <!--mainnav end-->
  </div>
</div>
<div id="container">
  <div class="sidebar">
    <h1> <img src="images/title_1.gif" alt="国内新闻" /> </h1>
    <div class="side_list">
      <ul>
        <li> <a href=‘#‘><b> 景区,如何不再依靠门票收入 </b></a> </li>
        <li> <a href=‘#‘><b> 高考期间中东部地区将现大范围降雨 </b></a> </li>
        <li> <a href=‘#‘><b> 山西离柳焦煤集团井下人行车发生事故6人死亡 </b></a> </li>
      </ul>
    </div>
    <h1> <img src="images/title_2.gif" alt="国际新闻" /> </h1>
    <div class="side_list">
      
    </div>
    <h1> <img src="images/title_3.gif" alt="娱乐新闻" /> </h1>
    <div class="side_list">
      <ul>
        <li> <a href=‘#‘><b> "星跳水立方"决战临近 陈楚生被华谊要求进前三 </b></a> </li>
        <li> <a href=‘#‘><b> 《新恋爱时代》登东方卫视 《非诚》元素遭删除 </b></a> </li>
        <li> <a href=‘#‘><b> 《海角七号》导演新片开机 吴宇森等出席 </b></a> </li>
        <li> <a href=‘#‘><b> 《致命黑兰》佐伊坐拥7种武器 暴力登陆全国院线 </b></a> </li>
      </ul>
    </div>
  </div>
  <div class="main">
    <div class="class_type"> <img src="images/class_type.gif" alt="新闻中心" /> </div>
    <div class="content">
      <ul class="class_date">
        <li id=‘class_month‘> <a href=‘#‘><b> 国内 </b></a> <a href=‘#‘><b> 国际 </b></a> <a href=‘#‘><b> 军事 </b></a> <a href=‘#‘><b> 体育 </b></a> <a href=‘#‘><b> 娱乐 </b></a> <a href=‘#‘><b> 社会 </b></a> <a href=‘#‘><b> 财经 </b></a> <a href=‘#‘><b> 科技 </b></a> <a href=‘#‘><b> 健康 </b></a> <a href=‘#‘><b> 汽车 </b></a> <a href=‘#‘><b> 教育 </b></a> </li>
        <li id=‘class_month‘> <a href=‘#‘><b> 房产 </b></a> <a href=‘#‘><b> 家居 </b></a> <a href=‘#‘><b> 旅游 </b></a> <a href=‘#‘><b> 文化 </b></a> <a href=‘#‘><b> 其他 </b></a> </li>
      </ul>
      <ul class="classlist">
        <li><a href=‘newspages/news_read.jsp‘> 深足教练组:说我们买球是侮辱 朱广沪常暗中支招 </a><span> 2013-06-06 01:03:51.0 </span></li>
        
        <p align="right"> 当前页数:[1/2]&nbsp; <a href="#">下一页</a> <a href="#">末页</a> </p>
      </ul>
    </div>
    <div class="picnews">
      <ul>
        <li> <a href="#"><img src="images/Picture1.jpg" width="249"  /> </a><a href="#">幻想中穿越时空</a> </li>
        <li> <a href="#"><img src="images/Picture2.jpg" width="249"  /> </a><a href="#">国庆多变的发型</a> </li>
        <li> <a href="#"><img src="images/Picture3.jpg" width="249"  /> </a><a href="#">新技术照亮都市</a> </li>
        <li> <a href="#"><img src="images/Picture4.jpg" width="249"  /> </a><a href="#">群星闪耀红地毯</a> </li>
      </ul>
    </div>
  </div>
</div>
  <%@include file="index-elements/index_bottom.html"%>
</body>
public class BaseDao {
    // 01. 基础内容的准备
   private static final String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
   private static final String url="jdbc:sqlserver://localhost:1433;DataBaseName=newsS2223";
   private static final String username="sa";
   private static final String pwd="6375196";
   
   //02, 接口对象的准备
   Connection con=null;
   PreparedStatement ps=null;
   public ResultSet rs=null;

   /**
    * 01.写一个用户获取到一个连接对象的方法,方法的返回值是Connection类型
    * @return   连接对象
    * @throws Exception
    */
   public Connection getConnection() throws Exception{
       Class.forName(driver);
       //什么条件下,构建connection对象
       if (con==null||con.isClosed()) {
           con=DriverManager.getConnection(url, username, pwd);
        }
       //同志们碰到一个
       return con;
   }
   
   
 
   
   /**
    * 执行查询操作  目的:返回一个读取器
    * @param sql  sql语句
    * @param objs  参数列表
    * @return     读取器对象
    * @throws Exception
    */
   public ResultSet  executeQuery(String sql,Object... objs) throws Exception{
       con=getConnection();
       ps = con.prepareStatement(sql);
       for (int i = 0; i < objs.length; i++) {
           ps.setObject(i+1, objs[i]);
       }
       rs= ps.executeQuery();
       return rs;
   }

   /**
    * 执行增删该操作
    * @param sql  sql语句
    * @param objs  参数列表
    * @return     受影响行数
    * @throws Exception
    */
   public int executeUpdate(String sql,Object... objs) throws Exception{
        con=getConnection();
        ps = con.prepareStatement(sql);
        for (int i = 0; i < objs.length; i++) {
               ps.setObject(i+1, objs[i]);
        }
        int count = ps.executeUpdate(); 
        return count;
   }
   
   
   
   
  /**
   * 回收连接资源
   * @throws Exception
   */
   public void closeAll() throws Exception{
       //倒着回收
       if(rs!=null){
           rs.close();
       }
       if (ps!=null) {
        ps.close();
       }
       if(con!=null){
           con.close();
       }
   }
   
}
public class NewsDetailDAOImpl extends BaseDao implements NewsDetailDAO{

    @Test
    public void testAll() throws Exception{
        List<NewsDetail> list= getAllNews() ;
        for (NewsDetail item : list) {
            System.out.println(item.getNewsTitle());
        }
    }
    
    
    public List<NewsDetail> getAllNews() throws Exception {
        List<NewsDetail> list=new ArrayList<NewsDetail>();
        String sql="select * from newsDetails";
        ResultSet rs = executeQuery(sql);
        if(rs!=null){
            while(rs.next()){
                //各个列
                //赋值给单个新闻对象的各个属性
                NewsDetail news=new NewsDetail();
                news.setNewsId(rs.getInt("newsId"));
                news.setNewsTitle(rs.getString("newsTitle"));
                news.setNewsContent(rs.getString("newsContent"));
                news.setNewsCreateDate(rs.getDate("newsCreateDate"));
                
                news.setNewsAuthor(rs.getString("newsAuthor"));
                news.setNewsCategoryId(rs.getInt("newsCategoryId"));
                
                
                
                //单个新闻对象加入新闻泛型
                list.add(news);
                
                
                
            }
            
        }
        return list;
    }
  
}
public class NewsDetail {
    private int newsId; 
    private String newsTitle;
    private String newsContent;
    private Date newsCreateDate;
    private String newsAuthor;
    private int newsCategoryId;
	public int getNewsId() {
		return newsId;
	}
	public void setNewsId(int newsId) {
		this.newsId = newsId;
	}
	public String getNewsTitle() {
		return newsTitle;
	}
	public void setNewsTitle(String newsTitle) {
		this.newsTitle = newsTitle;
	}
	public String getNewsContent() {
		return newsContent;
	}
	public void setNewsContent(String newsContent) {
		this.newsContent = newsContent;
	}
	public Date getNewsCreateDate() {
		return newsCreateDate;
	}
	public void setNewsCreateDate(Date newsCreateDate) {
		this.newsCreateDate = newsCreateDate;
	}
	public String getNewsAuthor() {
		return newsAuthor;
	}
	public void setNewsAuthor(String newsAuthor) {
		this.newsAuthor = newsAuthor;
	}
	public int getNewsCategoryId() {
		return newsCategoryId;
	}
	public void setNewsCategoryId(int newsCategoryId) {
		this.newsCategoryId = newsCategoryId;
	}
    
}

  

新闻发布系统

标签:

原文地址:http://www.cnblogs.com/Smile-123/p/5633743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!