新闻发布系统
2015-11-20 23:45
330 查看
新闻发布新闻的架构图是这样的
新闻的主界面是这样的
被框起来的是我们要从数据库里面读取的地方
从数据库读取新闻类型
代码如下,
在index.jsp里面的代码,这是两种方法,推荐使用第二种
然后就会出现图片上的效果
添加新闻
代码如下
servlet里面的代码
news-add.isp页面的代码
代吗中被标为红体的代码为主要代码,需要根据自己的数据库内容更改的
第三部分:
新闻分类
第四部分:
新闻的主界面是这样的
被框起来的是我们要从数据库里面读取的地方
从数据库读取新闻类型
代码如下,
public List<typeModel> getshowType() { String sql="SELECT * FROM newstype"; rs=executeSelect(sql); List<typeModel> list=new ArrayList<typeModel>(); try { while (rs.next()) { try { typeModel tm=new typeModel(); RefUtil.veryhappy(tm, rs); list.add(tm); } catch (Exception e) { e.printStackTrace(); } } } catch (SQLException e) { e.printStackTrace(); } return list; }
servlet里面的代码 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { TypeDaoImpl impl=new TypeDaoImpl(); List<typeModel> list = impl.getshowType(); request.setAttribute("toplist", list); request.getRequestDispatcher("/index.jsp").forward(request, response); }
在index.jsp里面的代码,这是两种方法,推荐使用第二种
<%--<% 第一种方法 List<typeModel> tupelist=(List<typeModel>)request.getAttribute("toplist"); for(typeModel itme:tupelist){ %> <a href='#'> <% out.print(itme.getTypeName()); } %> --%> 第二种方法: <c:forEach var="item" items="${toplist}"> <a href='#'>${item.typeName}</a> </c:forEach>
然后就会出现图片上的效果
添加新闻
代码如下
//写一个添加的方法 public boolean addnews(Newsinfo news) { Date datetime=new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = sdf.format(datetime); String sql="INSERT INTO NEWS(typeid,newsName,newsAuthor,newsTest,newsDateTime,npicpath) VALUES (?,?,?,?,?,?)"; Object[] paras={news.getTypeid(),news.getNewsName(),news.getNewsAuthor(),news.getNewsTest(),time,news.getNpicpath()}; boolean flase = executeUpdate(sql,paras); //closeAll(); return flase; }
servlet里面的代码
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); NewsDao dao=new NewsDaoImpl(); try { List<Newsinfo> list = (List<Newsinfo>) FormUtil.assembleObjectList(request, News.class); if( dao.addnews(list.get(0))){ } response.sendRedirect(request.getContextPath()+"/index.jsp"); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }
news-add.isp页面的代码
<p> <label> 主题 </label> <select name="typeid"> <option value="1">选择</option> <option value='1'> 国内 </option> <option value='2'> 国际 </option> <option value='3'> 军事 </option> <option value='4'> 体育 </option> <option value='5'> 娱乐 </option> <option value='6'> 社会 </option> <option value='7'> 财经 </option> <option value='8'> 科技 </option> <option value='9'> 健康 </option> <option value='10'> 汽车 </option> <option value='11'> 教育 </option> <option value='12'> 房产 </option> <option value='13'> 家居 </option> <option value='14'> 旅游 </option> <option value='15'> 文化 </option> <option value='16'> 其他 </option> </select> </p> <p> <!-- typeid,newsName,newsAuthor,newsTest,newsDateTime,npicpath--> <label> 标题 </label> <input name="newsName" type="text" class="opt_input" /> </p> <p> <label> 作者 </label> <input name="newsAuthor" type="text" class="opt_input" /> </p> <p> <label> 摘要 </label> <textarea name="newsDateTime" cols="40" rows="3"></textarea> </p> <p> <label> 内容 </label> <textarea name="newsTest" cols="70" rows="10"></textarea> </p> <p> <label> 上传图片 </label> <input name="npicpath" type="file" class="opt_input" /> </p>
代吗中被标为红体的代码为主要代码,需要根据自己的数据库内容更改的
第三部分:
新闻分类
第四部分:
相关文章推荐
- USB HID调试过程中碰到的一些问题
- 用例子理解hibernate的一级缓存
- Populating Next Right Pointers in Each Node
- 1. Spring Boot 1.2.5正式发布
- 【bzoj2733】 [HNOI2012] 永无乡
- Qt查询MYSQL中文乱码问题
- tcp_tw_recycle和tcp_timestamps导致connect失败问题13695
- 群集和ipvs初探(一)
- 关于APP在安卓系统上网络异常的故障分析.
- Linux教程【一】
- 安卓命名规范
- Win10 UWP 开发系列:支持异步的SQLite
- lsof处理df和du大小不一致的问题
- 产品经理入门必读干货 | PMCAFF精选问答整理(不断更新)
- WIFI P2P (WIFI直连)源码解析
- HTML5获取地理位置
- c# 读取txt文件中特定内容后的文字
- HeartBeat+MySQL+DRBD
- 根据输入显示一个人的出生日期(我的第二个python程序)
- 《c语言从入门到精通》看书笔记——第16章 网络套接字编程(下)——套接字