News Release System architecture

Source: Internet
Author: User

Realize:

Hierarchical architecture Diagram:

Key code: Console Output News content

Implementation class:

 PackageCn.news.impl;ImportJava.sql.ResultSet;Importjava.util.ArrayList;Importjava.util.List;Importorg.junit.Test;ImportCn.news.dao.BaseDao;ImportCn.news.dao.NewsDetailDao;ImportCn.news.entity.NewsDetail; Public classNewsdetaildaoimplextendsBasedaoImplementsnewsdetaildao{@Test Public voidTest ()throwsException {List<NewsDetail> list=getallnews ();  for(Newsdetail item:list) {System.out.println (item.getnewscontent ()); }} @Override PublicList<newsdetail> Getallnews ()throwsException {List<NewsDetail> list=NewArraylist<newsdetail>(); String SQL= "SELECT * FROM Newsdetails"; ResultSet RS=executeQuery (SQL); if(rs!=NULL)        {             while(Rs.next ()) {Newsdetail News=NewNewsdetail (); 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); }        }        returnlist; }}

Page displays news headlines and time:

New Newsservlet class inherits HttpServlet. Key code:

 PackageCn.news.servlet;Importjava.io.IOException;ImportJava.io.PrintWriter;Importjava.util.List;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportCn.news.entity.NewsDetail;ImportCn.news.impl.NewsDetailDaoImpl; Public classNewsservletextendsHttpServlet {/**     */     Public voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {doPost (request,response); }    /**         */     Public voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {//Instantiate DAONewsdetaildaoimpl dao=NewNewsdetaildaoimpl (); Try{List<NewsDetail> list=dao.getallnews (); Request.setattribute ("List", list); } Catch(Exception e) {e.printstacktrace (); } request.getrequestdispatcher ("/index.jsp"). Forward (request, response); }}

index.jsp

         class= "Classlist" >            <%      List<newsdetail>list= (list<newsdetail>) Request.getattribute ("list");              for (Newsdetail item:list)      {      %>      <li><a href= ' newspages/news_read.jsp ' ><%=item.getnewstitle ()%></a ><span><%=item.getnewscreatedate ()%></span></li>            <%      }             %>          <p align= "right" > Current page:[1/2]&nbsp; <a href= "#" > Next </a> <a href= "#" > Last </a > </p>      </ul>

Xml

News Release System architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.