JAVA-WEB项目新闻发布管理系统第四篇

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

重庆达渝仁科技官网:下面实现前台首页,新闻分类(体育新闻,科技新闻等),新闻列表分页。1、首页的jsp代码;[java]viewplaincopyprint?1.%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%2.!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//EN3.html4.head5.title新闻主页/title6.7./head8.bodyalign=center9.divalign=center10.%@includefile=head.jsp%11.tablestyle=border:6pxsolid#cccborder=1pxcellspacing=0pxwidth=1200pxheight=600px12.tr13.tdbr/br/br/br/14.divstyle=width:300pximgsrc=images/z_title.png//divbr/15.iframeframeborder=0width=100%height=100%scrolling=noname=allsrc=${pageContext.request.contextPath}/FrontNewsAction?action=findAllNews/iframe/td16.td17.br/br/br/br/18.divstyle=width:300pximgsrc=images/k_title.png//divbr/19.iframeframeborder=0width=100%height=100%scrolling=noname=technologysrc=${pageContext.request.contextPath}/FrontNewsAction?action=findAllNews&category_id=1/iframe/td20./tr21.tr22.td23.br/br/br/br/24.divstyle=width:300pximgsrc=images/t_title.png//divbr/25.iframeframeborder=0width=100%height=100%scrolling=noname=popularsrc=${pageContext.request.contextPath}/FrontNewsAction?action=findAllNews&category_id=2/iframe/td26.td27.br/br/br/br/28.divstyle=width:300pximgsrc=images/y_title.png//divbr/29.iframeframeborder=0width=100%height=100%scrolling=noname=sportssrc=${pageContext.request.contextPath}/FrontNewsAction?action=findAllNews&category_id=3/iframe/td30./tr重庆达渝仁科技官网:、新闻分类,新闻分页的实现:[java]viewplaincopyprint?1.packagecom.news.action;2.3.importjava.io.IOException;4.5.importjavax.servlet.ServletException;6.importjavax.servlet.http.HttpServletRequest;7.importjavax.servlet.http.HttpServletResponse;8.9.importcom.news.domain.News;10.importcom.news.domain.PageBean;11.importcom.news.domain.QueryInfo;12.importcom.news.service.FrontNewsService;13.importcom.news.utils.WebUtils;14.15.publicclassFrontNewsActionextendsBaseAction{16.publicvoidfindAllNews(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{17.try{18.//synchronized(this){19.QueryInfoinfo=WebUtils.request2bean(request,QueryInfo.class);20.FrontNewsServiceservice=newFrontNewsService();21.Stringcid=request.getParameter(category_id);22.intcategory_id=0;23.if(cid!=null){24.category_id=Integer.parseInt(cid);25.}26.PageBeanbean=service.pageQuery(info,category_id);27.System.out.println(大小是:+bean.getList().size());28.Stringjsp_Page=/news_jsps/News_All.jsp;29.System.out.println(category_id);30.if(category_id==1){31.jsp_Page=/news_jsps/News_Technology.jsp;32.}elseif(category_id==2){33.jsp_Page=/news_jsps/News_Sports.jsp;34.}elseif(category_id==3){重庆达渝仁科技官网:=/news_jsps/News_Popular.jsp;36.}37.request.setAttribute(pagebean,bean);38.request.getRequestDispatcher(jsp_Page).forward(request,response);39.//}40.41.}catch(Exceptione){42.e.printStackTrace();43.request.setAttribute(message,查看新闻列表失败!!);44.request.getRequestDispatcher(/message.jsp).forward(request,response);45.}46.}47.publicvoidfindNewsById(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{48.try{49.Stringnews_id=request.getParameter(news_id);50.FrontNewsServiceservice=newFrontNewsService();51.Newsnews=service.findNewsById(Integer.parseInt(news_id));52.request.setAttribute(news,news);53.request.getRequestDispatcher(/news_jsps/News_Information.jsp).forward(request,response);54.}catch(Exceptione){55.e.printStackTrace();56.request.setAttribute(message,查看新闻失败!!);57.request.getRequestDispatcher(/message.jsp).forward(request,response);58.}59.}60.}service层:[java]viewplaincopyprint?1.packagecom.news.service;2.3.importcom.news.dao.FrontNewsDao;4.importcom.news.domain.News;5.importcom.news.domain.PageBean;6.importcom.news.domain.QueryInfo;7.importcom.news.domain.QueryResult;8.9.publicclassFrontNewsService{10.11.FrontNewsDaodao=newFrontNewsDao();重庆达渝仁科技官网:(QueryInfoqueryInfo,intcategory_id)throwsException13.{14.//调用dao获得页面数据15.QueryResultqr=dao.pageQuery(queryInfo.getStartindex(),queryInfo.getPagesize(),category_id);16.//把获得页面数据封装到pagebean里面17.PageBeanpagebean=newPageBean();18.pagebean.setList(qr.getList());19.pagebean.setTotalrecord(qr.getTotalrecord());20.pagebean.setCurrentpage(queryInfo.getCurrentpage());21.pagebean.setPagesize(queryInfo.getPagesize());22.returnpagebean;23.}24.publicNewsfindNewsById(intnews_id)throwsException{25.returndao.findNewsById(news_id);26.}27.}dao层:[java]viewplaincopyprint?1.packagecom.news.dao;2.3.importjava.sql.Connection;4.importjava.sql.PreparedStatement;5.importjava.sql.ResultSet;6.importjava.util.ArrayList;7.importjava.util.HashMap;8.importjava.util.LinkedList;9.importjava.util.List;10.importjava.util.Map;11.12.importnet.sf.json.JSONArray;13.14.importorg.apache.commons.dbutils.DbUtils;15.16.importcom.news.domain.Category;17.importcom.news.domain.News;18.importcom.news.domain.QueryResult;19.importcom.news.utils.JdbcUtils;20.21.publicclassFrontNewsDao{

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功