新闻

刚刚接触这些东西不久掌握的东西也不是特别的牢固,以至于无法达到灵活应用的境界。不多说了,进入主题:

              新闻发布系统(News)

  下面我们看Index.jsp页面:我大致将它们分为了5块儿内容(反正我个人大致是这么认为的)

    

 

刚刚接触这些东西不久掌握的东西也不是特别的牢固,以至于无法达到灵活应用的境界。不多说了,进入主题:

              新闻发布系统(News)

  下面我们看Index.jsp页面:我大致将它们分为了5块儿内容(反正我个人大致是这么认为的)

    

  下面咱们一个个看,首先第一个:登陆

 

  当点击登陆的时候访问newsLoginServlet

  

                      

     //首先获取用户名与密码
     String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        //获取到账号密码后调用newsLogin类中的Login方法并返回一个Boolean值的
        newsLoginimpl login = new newsLoginimpl();
        if (login.Login(uname, upwd)) {
            request.getSession().setAttribute("txtName", uname);
            request.getRequestDispatcher("/newspages/admin.jsp").forward(request, response);
        }else {
            response.sendRedirect(request.getContextPath()+"/index.jsp");
        }            

    2.第二块、第三块、第四块都是在页面加载出来的时候一起显示的所以在访问的时候直接去访问一个Servlet最后在转发到index.jsp页面的           

        // 加载新闻发布系统左部分的分类新闻        
     // ---------------------------------------------------------------     
     //调用三次newsSeeTitleimpl类中的SeeTitle并传入一个类型值
     newsSeeTitleimpl titleimpl = new newsSeeTitleimpl();
        List<newsSeeTitlemodel> titlelistOne = titleimpl.SeeTitle(1);
        request.setAttribute("LeftTypeListOne", titlelistOne);
        
        List<newsSeeTitlemodel> titlelistTwo = titleimpl.SeeTitle(2);
        request.setAttribute("LeftTypeListTwo", titlelistTwo);
        
        List<newsSeeTitlemodel> titlelistThree = titleimpl.SeeTitle(3);
        request.setAttribute("LeftTypeListThree", titlelistThree);
        //分别将三个泛型放到作用域中
        // ---------------------------------------------------------------
        
        
        //加载新闻发布系统分类标题
        //----------------------------------------------------------------
        newsSeeTypeimpl newsSeeTypeimpl = new newsSeeTypeimpl();
        //调用newsSeeTypeimpl里面的SeeType方法查询出所有的分类标题
        List<newsSeeTypemodel> Typelist = newsSeeTypeimpl.SeeType();
        //将Typelist放置到作用域中
        request.setAttribute("SeeTypeList", Typelist);
        //----------------------------------------------------------------
        
        
        //按条件查询新闻
        String Result = request.getParameter("tid");
        //若tid为空那么证明是查看所有新闻
        if (Result==null||Result.equals("")) {
            //加载新闻发布系统Index.jsp页面  所有新闻
            newsSeeInfoimpl newsSeeInfoimpl = new newsSeeInfoimpl();
            List<newsinfomodel> SeeNewsInfoList = newsSeeInfoimpl.newsShow();
            //将装有所有新闻的泛型放到作用域中
            request.setAttribute("SeeNewsInfoList", SeeNewsInfoList);
        }else{
            //若tid不为空那么证明是查看的分类新闻
            //加载新闻发布系统Index.jsp页面  按条件加载新闻
            newsSelectInfoimpl newsSelectInfoimpl = new newsSelectInfoimpl();
            newsSelectInfoimpl n=new newsSelectInfoimpl();
            List<newsinfomodel> toDemandNewsInfoList=null;
                try {
                    toDemandNewsInfoList=n.toDemandNewsInfo(Integer.parseInt(Result));
                } catch (NumberFormatException e) {
                    System.out.println(e.getMessage());
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            //将查询出的分类新闻放置到作用域中
            request.setAttribute("SeeNewsInfoList", toDemandNewsInfoList);
        }
        //----------------------------------------------------------------

        //转发至index界面
        request.getRequestDispatcher("/index.jsp").forward(request, response);

 

posted @ 2015-11-30 01:52  by微笑99  阅读(267)  评论(0编辑  收藏  举报