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

📄 serchcard.java

📁 一个信息发布系统 基于jsp+servlet+tomcat 用户分管理员跟普通用户 普通用户有发布信息 查询信息 修改信息 回复信息 管理员拥有普通用户的功能 此外还具有删除信息 管理信息的回复的功能
💻 JAVA
字号:
package control;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.*;
import model.Card;
import java.util.*;
/**
 * 该Servlet需要从请求页面获取4个参数(pagenum,cpath,Keyword,Condition)
 * @author Administrator
 *
 */
public class SerchCard extends AddNewCategory
{
	public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    {
		req.setCharacterEncoding("gbk");
    	CardCom com = new CardCom("jdbc:mysql://localhost/mybbs","root", "root123");
    	Vector vc = new Vector();
    	int pagecount=1; //根据每页显示8行来计算出总共有多少页
    	int total=0;
    	int pagenum = Integer.parseInt((String)req.getParameter("pagenum"));
    	String condition = req.getParameter("Condition");  //查询条件  按作者  按内容或关键字
    	String CPath = req.getParameter("cpath");
    	String Keyword = (String)req.getParameter("Keyword").trim();
    	System.out.println("Serch card by keyword:"+Keyword);

    	if(Keyword.length()==0)
    		Keyword="all";
    	else if(Keyword.length()!=0)
    	{
    		String real = Keyword.replaceAll(" ", "");
    		if(real=="")
    			Keyword="all";
    	}
    	String Sort_Condition = (String)req.getParameter("sortcondition");      //2008.11.19修改  取得排序方式
    	System.out.println("SerchCard By: " + Sort_Condition);
    	if(condition.equals("ByContent"))    //如果按内容或关键字搜索
    	{
            /*Vector vc2 = com.getAllSerchCard(CPath,Keyword,Sort_Condition);
            for(int i = (pagenum-1)*8 ;(i< 8*pagenum)&&(i<vc2.size());++i)
            {
            	vc.add(vc2.get(i));
            }
            if(vc2!=null)
            {
            	total = vc2.size();
            	if(total % 8==0)
            		pagecount  = total/8;
            	else
            		pagecount = ((int)total/8)+1;	
            }*/
    		total = com.getCountSerchCard(CPath, Keyword, Sort_Condition);
    		if(total!=0)
            {
            	//total = vc2.size();
            	if(total % 8==0)
            		pagecount  = total/8;
            	else
            		pagecount = ((int)total/8)+1;
            	vc = com.getAllCardByKeyword(Keyword, CPath, pagenum, Sort_Condition);
            }
    	}
    	else //如果按作者名字搜索
        {
    		UserCom com2 = new UserCom("jdbc:mysql://localhost/mybbs","root", "root123");
    		total = com2.getTieziShuliang(Keyword);
    		if(total!=0)
    		{
    			 vc = com.getCardByUserName(Keyword, pagenum,Sort_Condition);
    			if(total % 8==0)
            		pagecount  = total/8;
            	else
            		pagecount = ((int)total/8)+1;
    		}                       
        }
    	req.setAttribute("Message","欢迎进入搜索结果页面");
    	req.setAttribute("NewsCount",new Integer(total) );
    	req.setAttribute("Condition", condition);
        req.setAttribute("Keyword", Keyword);
        req.setAttribute("cpath", CPath);
        req.setAttribute("pagenum",String.valueOf(pagenum));  //当前页数
        req.setAttribute("pagecount", String.valueOf(pagecount));//总共需要多少页面数
        req.setAttribute("allcard", vc);
        req.setAttribute("sortcondition", Sort_Condition); //2008.11.19修改  排序
        tiaoZhuan(req,res,"/ShowSerchCard.jsp");//跳转到该页面  显示所有的帖子Card

       
    }
}

⌨️ 快捷键说明

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