⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topiclistaction.java

📁 java struts source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      	  {
      		    //<search>
      		       sql+=" where ID='";
                     if("NULL".equals(expression)||"".equals(expression)) sql+=m_topicListForm .getInt("ID");
      		           else   sql+=expression;      		     
      		       sql+="'";
      		       sql+=" OR topicID='";
      		       if("NULL".equals(expression)||"".equals(expression)) sql+=m_topicListForm .getInt("ID");
      		           else   sql+=expression;      		     
      		       sql+="'";
      		       sql+=" order by child";
      		    //</search>
      	  }
      	  //sql+=" UNION select * from bbs as child where child.topicID=topic.ID";

         //<分页>
     	  m_topicListDAO.setLength(20);//设置每页显示记录数
     	  int ipage;//当前页
     	  try 
     	  {
     	      String page=request.getParameter("page");//分页参数,读取请求的当前页
     	      ipage=java.lang.Integer.parseInt(page,10);
     	  }
     	  catch (Exception e) 
         {
             ipage=m_topicListForm.getPage();
         } 
         if(ipage<1)ipage=1;
         ArrayList  col = (ArrayList)m_topicListDAO.findSQL(sql,ipage);//通过DAO对象查询数据
     	  request.setAttribute("topicList",col);  //保存数据	
     	 	
     	  String pagestr=m_topicListDAO.getPagestr(ipage);//分页字符串,分页内容
         if(!"search".equals(search))    //查找和全部显示两个不同的操作,其分页字符串不同,在此进行处理。如果是全部显示则去掉"search=search&"
      	  {
              pagestr=pagestr.replaceAll("search=search&","");
      	  }
      	  pagestr=pagestr.replace("?","?expression="+expression+"&");
      	  pagestr=pagestr.replace("action=find&","action=topicList&");
      	
     	  m_topicListForm.set("pagestr",pagestr); 
     	  m_topicListForm.set("action",action);  
          m_topicListForm.set("returnID",request.getParameter("returnID"));
          
          
          
          m_topicListForm.setInt("parentID",m_topicListForm .getInt("parentID")+1);	 	
     	  request.setAttribute("topicListForm",m_topicListForm);
         //</分页>
         
         //////////////
         if(!col.isEmpty())
         {
             NetForm myListForm =(NetForm)col.get(0);
             if(myListForm!=null)
             {
                 myListForm.setInt("hits",myListForm.getInt("hits")+1);
                 m_topicListDAO.update(myListForm ,String.valueOf(myListForm.getInt("ID")));      	     
             }
          }
         m_topicListDAO.Close();
         return mapping.findForward("topicList");
        
   }

   //定义方法revert,添加新回复:
    public ActionForward revert(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws Exception 
    {
         // 首先定义属性和变量以及设置初值
    	  NetForm m_topicListForm = (NetForm) form;	
      	  topicListDAO m_topicListDAO = new topicListDAO();  //定义DAO对象,用于实现数据库的各种操作
          
         if(m_topicListForm.getInt("topicID")!=0)
         {
             m_topicListForm.setInt("topicID",m_topicListForm.getInt("topicID"));
         }
         else
         {
             m_topicListForm.setInt("topicID",m_topicListForm.getInt("ID"));
         }
         m_topicListForm.setInt("child",m_topicListForm.getInt("child")+1);
         
         m_topicListForm.setInt("ID",0);
         
         HttpSession session = request.getSession();
          String username=(String)session.getAttribute(Constants.USER_NAME);
          m_topicListForm.setString("username",username);
          
          SimpleDateFormat lformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
          Calendar now = Calendar.getInstance(); 
          String nowstr = lformat.format(now.getTime()); 
          m_topicListForm.setString("datetime",nowstr);
          
          String body=m_topicListForm.getString("body");
          
          //body=body.replaceAll("<","&lt;");
          //body=body.replaceAll(">","&gt;");
          //body=body.replaceAll("&","&amp;");          
          
          body=body.replaceAll("\n","<br>");
          
          m_topicListForm.setString("body",body);
          m_topicListForm.setString("IP",request.getRemoteAddr());
         
        m_topicListDAO.create(m_topicListForm );      	     
         //m_topicListDAO.Close(); 	
        ///////////////查找数据库
       String action=request.getParameter("action");  //动作类型    		
      	  String search=request.getParameter("search");  //数据库查找方式
      	  String expression=request.getParameter("expression");    //参数,这里用于保存记录(行)的ID数据
      		
      	  if(action==null)action="find";
         if(search==null)search="UNsearch";
         if(expression==null)expression="";
         //action=toChinese(action);  //处理中文问题,实现编码转换,如果是用于MySQL,请加上这之一句
         expression=toChinese(expression);  //处理中文问题,实现编码转换,如果是用于MySQL,请去掉之一句
      	          	    
      	  ///////////////查找数据库
      	  //<sqlstr>
      		String sql="SELECT * FROM bbs";
      		//</sqlstr>

         ////SQL字符处理
      	  if("search".equals(search))
      	  {
      		    //<search>
      		       sql+=" where ID='";
                   sql+=m_topicListForm .getInt("topicID");    		     
      		       sql+="'";
      		       sql+=" OR topicID='";
      		       sql+=m_topicListForm .getInt("topicID");    		     
      		       sql+="'";
      		       sql+=" order by child";
      		    //</search>
      	  }

         //<分页>
     	  m_topicListDAO.setLength(20);//设置每页显示记录数
     	  int ipage;//当前页
     	  try 
     	  {
     	      String page=request.getParameter("page");//分页参数,读取请求的当前页
     	      ipage=java.lang.Integer.parseInt(page,10);
     	  }
     	  catch (Exception e) 
         {
             ipage=m_topicListForm.getPage();
         } 
         if(ipage<1)ipage=1;
         ArrayList col = (ArrayList)m_topicListDAO.findSQL(sql,ipage);//通过DAO对象查询数据
     	  request.setAttribute("topicList",col);  //保存数据	
     	 	
     	  String pagestr=m_topicListDAO.getPagestr(ipage);//分页字符串,分页内容
         if(!"search".equals(search))    //查找和全部显示两个不同的操作,其分页字符串不同,在此进行处理。如果是全部显示则去掉"search=search&"
      	  {
              pagestr=pagestr.replaceAll("search=search&","");
      	  }
      	  pagestr=pagestr.replace("?","?expression="+expression+"&");
      	  pagestr=pagestr.replace("action=find&","action=topicList&");
      	  
     	  m_topicListForm.set("pagestr",pagestr);   
          m_topicListForm.set("action",action);	 
          m_topicListForm.setInt("parentID",m_topicListForm .getInt("parentID"));	
          m_topicListForm.setString("image","http://");	
     	  request.setAttribute("topicListForm",m_topicListForm);
         //</分页>
         
         //////////////
         if(!col.isEmpty())
         {
             NetForm myListForm =(NetForm)col.get(0);
             if(myListForm!=null)
             {
                 myListForm.setInt("reverts",myListForm.getInt("reverts")+1);
                 m_topicListDAO.update(myListForm ,String.valueOf(myListForm.getInt("ID")));      	     
             }
          }
         m_topicListDAO.Close();
         return mapping.findForward("topicList");
   }
 
   //定义方法toinsertpage,转到添加新主题页面.
    public ActionForward toinsertpage(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws Exception 
    {
         NetForm m_topicListForm = (NetForm) form;
         m_topicListForm.setString("topic","");
         m_topicListForm.setString("body","");
         m_topicListForm.setString("image","http://");
         request.setAttribute("topicListForm",m_topicListForm);	
         // 首先定义属性和变量以及设置初值
    	 return mapping.findForward("toinsertpage");
   }
  
   //定义方法fileup,上传文件:
    public ActionForward fileup(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws Exception 
    {
        fileForm myform = (fileForm) form;
       
        try 
        {
             FormFile file = myform.getTheFile();                 
              InputStream stream = file.getInputStream();
              String filename=getServlet().getServletContext().getRealPath("/")+"/upload/"+file.getFileName();
              OutputStream bos = new FileOutputStream(filename);
              int bytesRead = 0;
              byte[] buffer = new byte[8192];
                       
               while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                    bos.write(buffer, 0, bytesRead);
               }
               bos.close();                       
               
                NetForm topicListForm = new NetForm();
               topicListForm.setInt("parentID",myform.getParentID());
               topicListForm.setString("image","upload/"+file.getFileName());
               request.setAttribute("topicListForm",topicListForm);
               return (mapping.findForward("success"));
        } 
        catch (Exception e) 
        {
            throw new RuntimeException(e.getMessage());
        }
    }
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -