News Release System architecture

Source: Internet
Author: User

Realize:

Hierarchical architecture Diagram:

Key code: Console Output News content

Implementation class:

Package Cn.news.impl;import Java.sql.resultset;import Java.util.arraylist;import java.util.list;import Org.junit.test;import Cn.news.dao.basedao;import Cn.news.dao.newsdetaildao;import Cn.news.entity.NewsDetail; public class Newsdetaildaoimpl extends Basedao implements newsdetaildao{@Test public void Test () throws Exceptio        n {list<newsdetail> list=getallnews ();        for (Newsdetail item:list) {System.out.println (item.getnewscontent ()); }} @Override public list<newsdetail> getallnews () throws Exception {List<newsdetail&gt ;                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; }}

Page displays news headlines and time:

New Newsservlet class inherits HttpServlet. Key code:

Package Cn.news.servlet;import Java.io.ioexception;import Java.io.printwriter;import java.util.list;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import     Cn.news.entity.newsdetail;import Cn.news.impl.newsdetaildaoimpl;public class Newsservlet extends HttpServlet {/** */public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioex            ception {doPost (request,response); }/** */public void DoPost (HttpServletRequest request, httpservletresponse response) throws Serv                Letexception, IOException {//Instantiate DAO Newsdetaildaoimpl dao=new Newsdetaildaoimpl ();                        try {list<newsdetail> list=dao.getallnews ();        Request.setattribute ("list", list);        } catch (Exception e) {e.printstacktrace (); }                Request.getrequestdispatcher ("/index.jsp"). Forward (request, response); }}

index.jsp

         <ul 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 = "#" > End </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.