新闻发布系统进程汇报
1。整个新闻发布系统全架构
2。实现登陆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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层代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | //解决乱码 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.实现注销
1 2 3 4 5 | 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.显示新闻列表
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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.编辑主题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.添加主题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.分页显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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; } |
以上就是我的新闻发布系统大概进程
增删改还没有写
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步