新闻发布系统进程汇报

1。整个新闻发布系统全架构

2。实现登陆

public boolean isLogin(UserInfo info) throws Exception {
		getConection();
		boolean flag=false;
		String sql="select count(1)as con from userinfo where uname=? and upwd=?";
		Object[]paras={info.getUname(),info.getUpwd()};
		rs=executeQuery(sql,paras);
		if(rs.next()){
		  int count=rs.getInt("con");
		  if(count>0){
			  flag=true;
		  }
		}
		return flag;
	}

}

  serlvet层代码:

		//解决乱码
		request.getCharacterEncoding();
		//解析
		String uname=request.getParameter("uname");
		String upwd=request.getParameter("upwd");
		UserInfo info=new UserInfo();
		info.setUname(uname);
		info.setUpwd(upwd);
		IUserInfoService service=new UserInfoServiceImpl();
		
		try{
			
			boolean flag=service.isLogin(info);
			
			if(flag){
				request.getSession().setAttribute("uname", uname);
				request.getRequestDispatcher("/newspages/admin.jsp").forward(request, response);
			}else{
				
				//request.getRequestDispatcher("/index.jsp").forward(request, response);
				response.sendRedirect("/NewsManagerSystem/index.jsp");
			}
		}catch(SQLException e){
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		}else{
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		}
	}

}

  3.实现注销

 

		String action=request.getParameter("action");		
		if("logout".equals(action)){
			request.getSession().removeAttribute("uname");
			//response.sendRedirect("/NewsManagerSystem/index.jsp");
				request.getRequestDispatcher("/index.jsp").forward(request, response);	

  

4.显示新闻列表

public List<NewsInfo> getAllNews() throws Exception {
		getConection();
		List<NewsInfo>list=new ArrayList<NewsInfo>();
		String sql="select * from newsinfo";
		rs=executeQuery(sql);
		while(rs.next()){
			NewsInfo info=new NewsInfo();
			info.setNtitle(rs.getString("ntitle"));
			info.setNcreateda(rs.getDate("ncreateda"));
			list.add(info);
		}
		return list;
	}

 5.编辑主题

	
	public List<Topic> getAllTopics() throws Exception {
       List<Topic> list=new ArrayList<Topic>();
       getConection();
       String sql="select * from topic";
       ResultSet rs= executeQuery(sql);
       
       while (rs.next()) {
	    Topic topic=new Topic();
	    topic.setTid(rs.getInt("tid"));
	    topic.setTname(rs.getString("tname"));
	    list.add(topic);
	}
      return list;
	}

6.添加主题

public boolean addTopic(Topic topic) throws SQLException {
			getConection();
		boolean flag=false;
		String sqlString="insert into topic values(?,?)";
        int count=0; 
        try {
			count=exeuteUpdate(sqlString,topic.getTid(),topic.getTname());
			if (count>0) {
				flag=true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	} 

 7.分页显示

 

public List<NewsInfo> getOnePageData(int pageindex, int pageSize) throws Exception{
		List<NewsInfo>list=new ArrayList<NewsInfo>();
		String sql="select * from newsinfo limit ?,?";
		Object[]paras={(pageindex-1)*pageSize,pageSize};
		getConection();
		rs=executeQuery(sql,paras);
		while(rs.next()){
			NewsInfo info=new NewsInfo();
			info.setNtitle(rs.getString("ntitle"));
			info.setNcreateda(rs.getDate("ncreateda"));
			list.add(info);
		}
		
		return list;
	}

 以上就是我的新闻发布系统大概进程 

   增删改还没有写

转载于:https://www.cnblogs.com/wangbenqing/p/6775014.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package org.news.servlet.back; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.news.entity.Topic; import org.news.service.TopicService; import org.news.service.impl.TopicServiceImpl; /** * 后台主题Servlet */ public class TopicServlet extends HttpServlet { private static final Logger logger = Logger.getLogger(TopicServlet.class); private TopicService topicService = new TopicServiceImpl(); public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); // 设置响应内容格式和编码格式,相当于JSP的page指令的contentType属性 HttpSession session = request.getSession(); // 获取session对象 PrintWriter out = response.getWriter(); // 获取out对象(响应输出字符流) ServletContext application = super.getServletContext(); // 获取application对象(Servlet上下文对象) String contextPath = request.getContextPath(); // 获取上下文路径(重定向) String opr = request.getParameter("opr"); // 获取请求参数opr的值,opr代表是什么类型的请求 if (opr == null) { // 如果不传参数opr时,不处理会引发NPE(NullPointerException) response.sendError(500, "opr参数是必须的"); // 发送错误代码500(内部代码错误)及提示信息,可在web.xml中定制报错页面 return; } switch (opr) { case "addTopic": // 添加主题操作: http://localhost:8080/NewsManagerSystem/newspages/topic?opr=addTopic addTopic(request, response); break; case "modifyTopic": // 获取要修改的主题操作: http://localhost:8080/NewsManagerSystem/newspages/topic?opr=modifyTopic&tid=29 modifyTopic(request, response); break; case "domodifyTopic": // 修改主题操作: http://localhost:8080/NewsManagerSystem/newspages/topic?opr=domodifyTopic domodifyTopic(request, response); break; case "deleteTopic": // 删除主题操作: http:/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值