首页如上

类图如下:

添加新闻的方法(dao):

 public boolean Add(News news) {
boolean flag=false;
Connection con =getConnectionData();
QueryRunner queryRunner = new QueryRunner();
String sql="INSERT INTO newscon(newstype,title,author,abstrac ,content,picture) VALUE(?,?,?,?,?,?)";
Object[] paras={news.getNewstype(),news.getTitle(),news.getAuthor(),news.getAbstrac(),news.getContent(),news.getUrl()};
int count=0;
try {
count= queryRunner.update(con,sql,paras);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(),e);
}
closeAll();
if(count>0){
flag=true;
}
return flag;
}

servlet方法:

 public class AddNews extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
if(request.getMethod().equals("GET")){
request.getRequestDispatcher("/newspages/news_add.jsp").forward(request,
response);
}else {
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort() + path + "/";
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession();
boolean flag=false;
try {
List<News> list = (List<News>) FormUtil.assembleObjectList(request,News.class);
News news = list.get(0);
NewsDaoimpl dao=new NewsDaoimpl();
flag = dao.Add(news); } catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
if (flag) {
response.sendRedirect(path); }else {
request.getRequestDispatcher("/index.jsp").forward(request,
response);
} }
} }

插入标题:

 public class AddTitleServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
if (request.getMethod().equals("GET")) {
request.getRequestDispatcher("/newspages/news_add.jsp").forward(
request, response);
} else {
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession();
boolean flag = false;
try {
List<Topic> list = (List<Topic>) FormUtil.assembleObjectList(
request, Topic.class);
Topic topic = list.get(0);
NewsDaoimpl dao = new NewsDaoimpl();
flag = dao.AddTitle(topic); } catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
if (flag) {
response.sendRedirect(path); } else {
request.getRequestDispatcher("/index.jsp").forward(request,
response);
}
}
} }

标题的动态加载:

index:

 <c:forEach var="item" items="${requestScope.Toplist}">
<a style="color:blue;font-size:16px;" href='${pageContext.request.contextPath }/DoIndexServlet?id=${item.nid}'>
${item.newstype}
</a>
</c:forEach>
</li>
</ul>
<ul class="classlist">
<c:forEach var="item" items="${requestScope.newsList }">
<li><a href='newspages/news_read.jsp'>${item.title }</a>
<span>
<c:forEach var="item1" items="${TimeList}">
${item1.beginDatetime}
</c:forEach>
</span>
</li>
</c:forEach>

impl:

 public List<Topic> AllTitle() {

         Connection con=getConnectionData();
String sql="select nid,newstype from type";
QueryRunner query=new QueryRunner();
List<Topic> list=null;
try { list= query.query(con, sql,new BeanListHandler<Topic>(Topic.class));
} catch (SQLException e) {
new RuntimeException(e.getMessage()); }
return list;
}

新闻web小酌的更多相关文章

  1. Java web 小测验

    题目要求: 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1分) 3性别:要求用单 ...

  2. 张小龙的野心:用小程序重构web|小程序好处及可能的不足

    一:张小龙的野心:用小程序重构web 一 很多年以前,张小龙写了一款软件:Foxmail. 这款软件当年有数百万用户,这是一个相当庞大的量,因为彼时网民也只有千万当量级的规模. 我是一个非常忠实的用户 ...

  3. WEB 小案例 -- 网上书城(四)

    针对于这个小案例我们今天讲解结账操作,也是有关这个案例的最后一次博文,说实话这个案例的博文写的很糟糕,不知道该如何去表述自己的思路,所以内容有点水,其实说到底还是功力不够. 处理思路 点击结账,发送结 ...

  4. web小知识点

    写在前面: 该篇是个人平时对web前端小知识点的总结,会不定时更新...... 如有错误,敬请批评指正. 正文: 1.WWW是World Wide Web的缩写. 2.HTML(Hyper Text ...

  5. go语言实现一个简单的登录注册web小程序

    最近学习golang也有一段时间了,基础差不多学了个大概,因为本人是java程序员,所以对web更感兴趣.根据<go web编程>中的例子改编一个更简单的例子,供新手参考,废话不多说,上菜 ...

  6. 【WEB小工具】EncodingFilter—设置全局编码

    1.我们知道,如果是POST请求,我们需要调用request.setCharacterEncoding("utf-8") 方法来设计编码. public void doGet(Ht ...

  7. 【WEB小工具】BaseServlet—一个Servlet处理多个请求

    package cn.itcast.test.web.servlet; import java.io.IOException; import java.io.PrintWriter; import j ...

  8. macaca测试web小例子

    上午刚把macaca的环境在公司的电脑上吧web 端的环境给搭建好,于是乎,看看网上的例子,看看官方的文档 https://macacajs.github.io/wd.py/ 可以在这个链接看到原滋原 ...

  9. WEB 小案例 -- 网上书城(一)

    距离上次写博客有两周了吧,最多的原因就是自己期末考试了,上课没听就只能在期末狠狠的复习了,毕竟已经挂科了.当然还是因为自己懒吧!!!废话不多说开始我们今天的正题,网上书城! 一. 新建数据表(MySQ ...

随机推荐

  1. 尽量使用ToUpper比较,避免使用ToLower

    在编码时尽量使用ToUpper比较,避免使用ToLower,因为微软对ToUpper进行了优化,以下为测试结果: public void TestToLower() { Stopwatch watch ...

  2. oracle 查询dblink的方法

    oracle 查询dblink的方法: SYSDBA登录, sys登录 SELECT * FROM SYS.link$;

  3. BZOJ 1072 排列

    Description 给一个数字串\(s\)和正整数\(d\), 统计\(s\)有多少种不同的排列能被\(d\)整除(可以有前导\(0\)).例如\(123434\)有\(90\)种排列能被\(2\ ...

  4. About javascript language

    Core http://www.cnblogs.com/leoo2sk/archive/2010/12/19/ecmascript-scope.html function(arguments) fun ...

  5. Js中的window.parent ,window.top,window.self详解

    在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...

  6. 模拟I2C从机

    模拟I2C主机的比较多,但是从机相对主机而言要难很多,这个供大家借鉴. 这个从机程序支持主机对它的随机写和随机读,连续读和连续写没做,有兴趣的可以完善下,呵呵. //Microcontrol CODE ...

  7. TWinControl的刷新过程(5个非虚函数,4个覆盖函数,1个消息函数,默认没有双缓冲,注意区分是TCustomControl还是Windows原生封装控件,执行流程不一样)

    前提条件:要明白在TWinControl有以下四个函数的存在,注意都是虚函数: procedure Invalidate; override;procedure Update; override;pr ...

  8. c# 集合ArrayList;特殊集合Stack、Queue

    一)  ArrayList 1.foreach遍历数组中各个元素,执行内部语句 2.  3. 4.  myarry.Clear();//将集合清空 bool b = myarry.Contains(3 ...

  9. C#代码实现隐藏任务栏、开始菜单和禁用任务管理

    一:截图,主要是调用系统接口和更改注册表实现功能 二:代码 using System; using System.Collections.Generic; using System.Linq; usi ...

  10. 阿里云ECS试用

    公司在推一个大项目,感觉阿里云挺好用的,自己搞了台小机器平时可以跑着玩,而且可以做个跳板机,平时学校里的收费网直接用跳板机就可以访问了,直接写个脚本在自己机器上跑一下: #!/usr/bin/expe ...