JAVA-WEB項目新聞發布管理系統第四篇_第1頁
JAVA-WEB項目新聞發布管理系統第四篇_第2頁
JAVA-WEB項目新聞發布管理系統第四篇_第3頁
JAVA-WEB項目新聞發布管理系統第四篇_第4頁
JAVA-WEB項目新聞發布管理系統第四篇_第5頁
已閱讀5頁,還剩7頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、F面實現前臺首頁,新聞分類(體育新聞,科技新聞等),新聞列表分頁 1、首頁的jsp代碼; java view plaincopyprint? 1. 2. 3. 4. 5. 新聞主頁 6. 6. 7. vbody align=center 8. 9. 10. vtable style=border:6px solid #ccc border=1px cellspacing=0px width=1200px height=600px 11. 12. vbr/vbr/vbr/ 13. vdiv style=width:300pxvimg src=images/z_title.png/v/divvbr

2、/ 14. viframe frameborder=0 width=100% height=100% scrolling=noname=all src=$pageC ontext.request.contextPath/FrontNewsAction?action=findAIINews v/iframev/td 15. vtd 16. vbr/vbr/vbr/vbr/ 17. vdiv style=width:300pxvimgsrc=images/k_title.png/v/divvbr/ 18. viframe frameborder=0 width=100% height=100%sc

3、rolling=no name=technology src= $pageContext.request.contextPath/FrontNewsAction?action=findAIINewsbo)J!0 !(P!-Xjo69;eo)unu!JdinoiU9;sXs 乙 !udsf|v-s/v9N/sdsr s/v9u/u=96ec|-dsf 6uu;s82 t()oz!s()iS!iiobuEoq+” :者、 Ju|MchnouoisAs22 pi-XjoBsieoojuisnosBed soiAJss =uesq uesgsBed93 92 !(P!O);u|9SjedJ969;u|

4、=p!-Xjo69;eo書乙 (l|nu=jp!o)j!乙 !0=P!-Xjo6s;eo ;uiz乙 !(11P!-Xjo69;eo11)J9;9LuejecH96iS9nb9J=p!O 6uu;sJ乙 iOaOlAJSSSMSNlUOJd /V9U=90IAJ9S SOlAJSSSMSNlUOJjOS !(sse|o oju|Xjsno isonbai)UEoq乙isonbars|!inqo/v=ojU! oju|Xjsnoq, (siq;) psziuojqouXs/.初 心21 uoi;dsox3 s/vojq; (ssuodssj ssuodssyiaiAJSsduHlssnbsj ;

5、S9nb9y;9|AJ9sduH)SM9NIIVPUU piOA oi|qnd 91, Juoipvsseg spusxs uoipvsmsniuojj ssep oi|qnd 申 劃 !s|!inc|9AA S|!in s/v9U LU00 podiui ISOlAJSSSMSNlUOJd SOlAJSS SMSU LUOO podiui 引 iojuiXjsno uieiuop sMsu Luoo podiui luesgsBeduieiuopsMsumoo podiuioi ISMSNUieiuopsMsumoo podiui6 8 !9SUods9y;9|AJ9sduHclui|i9|

6、AJ9sxeAef podiuij_ !;S9nb9y;9|AJ9sduHclui|i9|AJ9sxeAef podiui9 !U0!;d90X3;9|AJ9S ;9|AJ9S XBAef podiuig P !uoi;d9OX3oro!BAef podiui .乙 iuoipe sMsumoo s6e|oecl 4 6lUIJdAd00U!B|d M9IA bab| V|Ul|/ 龍 37. request.setAttribute(pagebean, bean); 38. request.getRequestDispatcher(jsp_Page).forward(request, res

7、ponse); 39. / 40. 41. catch (Exception e) 42. e.printStackTrace(); 43. request.setAttribute(message,查看新聞列表失敗!!); 44. request.getRequestDispatcher(/message.jsp).forward(request, response); 45. 46. 47. public void findNewsByld(HttpServletRequest request,HttpServletResponse response) throws Excepti on

8、48. try 49. String news_id=request.getParameter(news_id); 50. FrontNewsService service=new FrontNewsService(); 51. News news= service.findNewsByld(lnteger.parselnt(newsd); 52. request.setAttribute(news, news); 53. request.getRequestDispatcher(/news_jsps/News_Information.jsp).forward(request, respons

9、e); 54. catch (Exception e) 55. e.printStackTrace(); 56. request.setAttribute(message,查看新聞失敗! !); 57. request.getRequestDispatcher(/message.jsp).forward(request, response); 58. 59. 60. service 層: java view plaincopyprint? 1. package com.news.service; 2. 2. import com.news.dao.FrontNewsDao; 3. import

10、 com.news.domain.News; 4. import com.news.domain.PageBean; 5. import com.news.domain.Querylnfo; 6. import com.news.domain.QueryResult; 8. 7. public class FrontNewsService 10. 8. FrontNewsDao dao=new FrontNewsDao(); 9. public PageBean pageQuery(QueryInfo querylnfo,int category_id) throws Exception 10

11、. 11. /調用dao獲得頁面數據 12. QueryResult qr= dao.pageQuery(querylnfo.getStartindex(), querylnfo.getPagesize(),category_id); 13. /把獲得頁面數據封裝到 pagebean里面 14. PageBean pagebean=new PageBean(); 15. pagebean.setList(qr.getList(); 16. pagebean.setTotalrecord(qr.getTotalrecord(); 17. pagebean.setCurrentpage(query

12、lnfo.getCurrentpage(); 18. pagebean.setPagesize(querylnfo.getPagesize(); 19. return pagebean; 20. 21. publicNews findNewsByld(int news_id) throws Exception 22. return dao.findNewsByld(news_id); 23. 24. dao 層: java view plaincopyprint? 1. package com.news.dao; 2. 2. import java.sql.Connection; 3. imp

13、ort java.sql.PreparedStatement; 4. import java.sql.ResultSet; 5. import java.util.ArrayList; 6. import java.util.HashMap; 7. import java.util.LinkedList; 8. import java.util.List; 9. import java.util.Map; 11. 10. import net.sf.json.JSONArray; 13. 11. import mons.dbutils.DbUtils; 15. 12. import com.n

14、ews.domain.Category; 13. import com.news.domain.News; 14. import com.news.domain.QueryResult; 15. import com.news.utils.JdbcUtils; 20. 16. public class FrontNewsDao 17. public QueryResult pageQuery(int startindex,int pagesize,int category_id) throws Exception 18. 19. Connection conn=null; 20. Prepar

15、edStatement st=null; 21. ResultSet rs=null; 22. QueryResult qr=new QueryResult(); 23. try 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. conn=JdbcUtils.getConnection(); St

16、ring sql=select * from tb_news order by id desc limit ?,?; System.out.println(分類 id : +category_id); if(category_id0) sql=select * from tb_news where category_id=? order by id desc limit ?,? st=conn.prepareStatement(sql); if(category_id0) st.setlntQ ,category_id ); st.setlntp, startindex); st.setlnt

17、p, pagesize); else st.setlntQ, startindex); st.setlnt2, pagesize); rs=st.executeQuery(); List list=new LinkedList(); while(rs.next() News n=new News(); n.setTitle(rs.getString(title); n.setContent(rs.getString(content); n.setNews_id(rs.getlnt(id); n.setDate(rs.getDate(date); n.setCategory(new Catego

18、ry(rs.getlnt(category_id),null); list.add(n); if(category_id0) sql=select count(*) from tb_news where category_id=?; else sql=select count(*) from tb_news; st=conn.prepareStatement(sql); if(category_id0) st.setlntQ ,category_id ); rs=st.executeQuery(); if(rs.next() qr.setTotalrecord(rs.getlnt(l); qr

19、.setList(list); return qr; catch (Exception e) 73. / TODO Auto-generated catch block 74. throw new Exception(e); 75. finally 76. DbUtils.closeQuietly(conn, st, rs); 77. 78. 79. public News findNewsByld(int news_id) throws Exception 80. Connection conn=null; 81. PreparedStatement st=null; 82. ResultS

20、et rs=null; 83. try 84. conn=JdbcUtils.getConnection(); 85. String sql=select * from tb_news where id=?; 86. st=conn.prepareStatement(sql); 87. st.setlnt(1, news_id); 88. rs=st.executeQuery(); 89. News n=new News(); 90. if(rs.next() 91. 92. 93. n.setTitle(rs.getString(title); 94. n.setContent(rs.get

21、String(content); 95. n.setNews_id(rs.getInt(id); 96. n.setDate(rs.getDate(date); 97. n.setCategory(new Category(rs.getlnt(category_id),null); 98. 99. return n; 100. catch (Exception e) 101. / TODO Auto-generated catch block 102. throw new Exception(e); 103. finally 104. DbUtils.closeQuietly(conn, st

22、, rs); 105. 106. 107. 工具類: java view plaincopyprint? 1. package com.news.utils; 2. import java.sql.Connection; 3. import java.sql.ResultSet; 4. import java.sql.SQLException; 5. import java.sql.Statement; 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.

23、31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.sql.DataSource; import com.mchange.v2.c3pO.ComboPooledDataSource; import com.mchange.v2.c3pO.DataSources; public class J

24、dbcUtils implements ServletContextListener private static ComboPooledDataSource ds=null; static try ds=new ComboPooledDataSource。; catch (Exception e) / TODO: handle exception throw new ExceptionlnlnitializerError(e); public static DataSource getDateSource() return ds; public static Connection getCo

25、nnection() throws SQLException return ds.getConnection(); public static void release(Connection conn,Statement st,ResultSet rs) if(rs!=null) try rs.close(); catch (Exception e) / TODO: handle exception e.printStackTrace(); rs=null; if(st!=null) try st.close(); catch (Exception e) / TODO: handle exce

26、ption e.printStackTrace(); 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. st=null; if(conn!=null) try conn.close(); catch (Exception e) / TODO: handle exception e.printStackTrace(); conn=null; public voi

27、d contextDestroyed(ServletContextEvent argO) / TODO Auto-generated method stub System.out.println( ?); try DataSources.destroy(ds); catch (Exception e) e.printStackTrace(); try Thread.sleep(OOO); catch (InterruptedException e) e.printStackTrace(); public void contextlnitialized(ServletContextEvent a

28、rg0) / TODO Auto-generated method stub 系統的主要源碼就貼到這,接下來提供源碼下載 整個項目的源碼下載 四、一輩子孤單并不可怕,如果我們可以從中提煉出自由,那我們就是幸福的。許多長久的關系都以為忘記了當初所堅持與擁有的,最后又開始羨慕起孤單的人。 五、戀愛,在感情上,當你想征服對方的時候,實際上已經在一定程度上被對方征服了。首先是對方對你的吸引,然后才是你征服對方的欲望。 六、 沒有心如刀割,不再依依不舍,只有,沉默相隔 七、和你在一起只是我不想給任何人機會。 八、一個人總要走陌生的路,看陌生的風景,聽陌生的歌,然后在某個不經意的瞬間,你會發現,原本是費盡

29、心機想要忘記的事情真的就那么忘記了。 九、無論我們愛過還是就這樣錯過,我都會感謝你。因為遇見你,我才知道思念一個人的滋味;因為遇見你,我才知道感情真的不能勉強;因為遇見你,我才知道我的心不是真的死了; 因為遇見你,我才知道我也能擁有美麗的記憶。所以,無論你怎么對待我,我都會用心去寬恕你的狠,用心去銘記你的好。 十、愛情需要的是彼此互相的照顧,當我們心愛的人累了,我們不是坐在一邊不理,而是多陪對方談談心,對方需要什么的時候,自己盡量的滿足對方的需求,至少可以讓對方知道,在 自己身邊的感覺是如此的溫暖。 十一、自從你出現後,我才知道原來有人愛是那麼的美好 十二、有的人與人之間的相遇就像是流星,瞬間迸發出令人羨慕的火花,卻注定只是匆匆而過。 十三、有一些人,這一輩子都不會在一起,但是有一種感覺卻可以藏在心里守一輩子。 十四、不要輕易說愛,許下的承諾就是欠下的債! 十五、不管你是多么的愛對方,但千萬不可當第三者。細想,默然。因為知道,這樣的故事一開始便注定了結局,一開始就注定在這個故事里,很多人會

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論