首页如上

类图如下:

添加新闻的方法(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. UFLDL实验报告2:Sparse Autoencoder

    Sparse Autoencoder稀疏自编码器实验报告 1.Sparse Autoencoder稀疏自编码器实验描述 自编码神经网络是一种无监督学习算法,它使用了反向传播算法,并让目标值等于输入值, ...

  2. bzoj3141: [Hnoi2013]旅行

    Description   Input 第 一行为两个空格隔开的正整数n, m,表示旅行的城市数与旅行所花的月数.接下来n行,其中第 i行包含两个空格隔开的整数Ai和Bi,Ai表示他第i个去的城市编号 ...

  3. Expert Shell Scripting

    Expert Shell Scripting 好好学习这本书

  4. Java中接口与实例化

    一.问题引入         前两天学代理模式的时候想到的,接口可不可以new呢?         接口是特殊的抽象类,接口的方法都默认为  public  abstract  的... 抽象的方法不 ...

  5. Nine Great Books about Information Visualization

    Nine Great Books about Information Visualization Maybe it’s anachronistic to celebrate static, print ...

  6. 禁用窗体关闭按钮(使用GetWindowLong修改GWL_STYLE)

    一般我们不想让窗体能够关闭, 首先想到的是在OnCloseQuery事件里设置CanClose := False, 不过在某些情况下这个会和程序关闭窗体的业务逻辑产生冲突 所以写了下面这个函数, 可以 ...

  7. nodejs触发事件的两种方式

    nodejs触发事件的两种方式: 方式之一:通过实例化events.EventEmitter //引入events模块 var events = require('events'); //初始化eve ...

  8. mt7601 driver

    http://download.csdn.net/detail/u011500307/7011649 http://my.oschina.net/fgq611/blog/180750 http://b ...

  9. POJ-3294-Life Forms(后缀数组-不小于 k 个字符串中的最长子串)

    题意: 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. 分析: 将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组. 然后二分答案,将后缀分成若干组,判断 ...

  10. Javascript面向对象编程(二):构造函数的继承 by 阮一峰

    今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有一个"动物"对象的构造函数. function Animal(){ this.species = & ...