1.在web中建立一個InitServlet檔案,繼承httpServlet
2.new一個dbUtil,newsDao,newsTypeDao。
3.重寫init(config)方法,通過config的getServletContext方法擷取一個servletContext類型的application對象
4.定義一個私有void的refreshSystem方法,參數是servletContext類型的application,連接配接資料庫.
5.調用refreshSystem方法(this.refreshSystem(application))
6.配置web.xml。在sevlet中加一個load-on-startup,值為1.
7.建立一個newsServlet檔案,繼承httpServlet
8.重寫doGet和doPost方法。
9.在doPost方法中,定義一個string類型的action,從request中取值。如果action的值是list,則調用newsList方法。
10.建立一個newsList方法,參數為request和response。定義一個string類型的typeId,從request中取值。将news/newsList.jsp進行setAttribute成一個mainPage,然後進行request轉發到foreground/newsTemp.jsp
11.配置web.xml
12.在foreground中建立一個news檔案夾和newsTemp.jsp,在news檔案夾中建立一個newsList.jsp
二. Servlet啟動項——最新新聞加載1.将indexservlet中的newestNewsList整段拷過來,将newestNewsList放入application中
三. Servlet啟動項 ——資訊類别加載1.通過newsTypeDao的newsTypeList方法擷取一個List類型對象為NewsType的newsTypeList,将newsTypeList放入application中
四. Servlet啟動項 ——熱門新聞加載1.寫一個sql語句。select * from t_news order by click desc limit 0,8
2.通過newsDao的newsList方法擷取一個List類型對象為News的hotNewsList,将hotNewsList放入application中