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

📄 searchoutthings.java

📁 第一次上传文件还不知道可以不可以, 有什么问题和我联系,有会C++的么想请人教教我 好不好用自己下下来用用不就知道了??? 里面有源码及数据库
💻 JAVA
字号:
/**
 * SearchOutthings.java
 * author:liuhaijing
 * @version 1.0
 */
 
 package mydesign;//包名

import java.io.*;
import mydesign.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public class SearchOutthings extends HttpServlet
{
	String strSQL="";
	String strSQL1="";
    
    //Initialize global variables
    public void init() throws ServletException 
    {
    }
    
    //接收POST请求,执行数据库操作,分页显示结果保存到session中,把视图派发到下一个页面
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    	HttpSession session=request.getSession(true);
        request.setCharacterEncoding("gb2312");
        response.setContentType("text/html; charset=gb2312");
        PrintWriter out=response.getWriter();
        OutthingsControl outthingscontrol=new OutthingsControl();
        PageBean pageCt1=new PageBean();
        int page=1;
      
        if(session.getAttribute("strSQL")!=null)    //判断客户机的请求是接受查询表单数据,还是执行翻页、修改或删除
        {
        	strSQL=(String)session.getAttribute("strSQL");
        	if(session.getAttribute("jumppage")==null)    //判断客户机的请求是翻页还是执行修改或删除后的显示
        	{
        		String x=request.getParameter("jumppage");    //得到要显示的页码  
        		page=Integer.parseInt(x);
   	     		String update=request.getParameter("update");
        		String del=request.getParameter("del");
      	  		if(update!=null||del!=null)    //判断客户机的请示是翻页还是修改或者删除,修改删除执行
        		{        	
        			int select=Integer.parseInt(request.getParameter("select"));
        			pageCt1=(PageBean)session.getAttribute("pageCt1");    //得到该页显示的数据
        			ArrayList search=pageCt1.getResult();
        			Outthings outthings=(Outthings)search.get(select);    //得到要操作的数据
        			session.setAttribute("jumppage",x);    //保存要显示的页码
        			try
        			{
        				if(update!=null)    //保存要修改的数据,并派发到修改页面
        				{
        					session.setAttribute("outthings",outthings);
        					out.print("<script>window.location.href='updateoutthings.jsp'</script>");
        				}else{        //执行删除,重新查询
        					outthingscontrol.DelOutthings(outthings);
							//如果删除的数据是最后一页惟一一行数据,则将把要显示的页码减1
        					if(page==pageCt1.maxPage&&pageCt1.maxRowCount%pageCt1.rowsPerPage==1)    
        					{
        						session.setAttribute("jumppage",String.valueOf(page-1));
        					}
							outthingscontrol.close();
        					out.print("<script>alert('删除成功!');window.location.href='/MyDesign/SearchOutthings'</script>");    //重新查询,并显示原页或前一页
        				}
        			}catch(Exception e)
        			{
        			    System.out.print("SearchOutthingsServlet error:"+e.getMessage());           
        			}
        		}
        	}else{
        			page=Integer.parseInt((String)session.getAttribute("jumppage"));    //得到要显示的页码
         			session.setAttribute("jumppage",null);    //要显示的页码清空
        	}
        }else{    //得到表单数据
        	String a1=request.getParameter("studentid");
        	String a2=request.getParameter("thing");
        	String a3=request.getParameter("outtime");
        	strSQL=getStrSQL(a1,a2,a3);
        }
        try
        {
        	session.setAttribute("strSQL",strSQL);
        	strSQL1="select count(*) from outthings"+strSQL;    //计算查询总数的查询语句
        	strSQL="select top "+page*pageCt1.rowsPerPage+" * from outthings"+strSQL;    //第一页到要显示页码的查询语句
         	if(page==0)  out.print("<script>alert('已经无符合条件的房间!');window.location.href='searchoutthings.jsp'</script>");    //符合条件的数据为0时将页面派发到查询页面
        	pageCt1=outthingscontrol.listData(page,this);    //得到该页要显示的数据
        	outthingscontrol.close();
         	if(pageCt1.getResult().size()==0)  out.print("<script>alert('无符合条件的房间!');window.location.href='searchoutthings.jsp'</script>");    //符合条件的数据为0时将页面派发到查询页面
			session.setAttribute("pageCt1",pageCt1);    //保存要显示的数据
        	out.print("<script>window.location.href='searchoutthingsresult.jsp'</script>");    //将视图派发到下一个页面
        }
        catch(Exception e)
        {
            System.out.print("SearchHouse Servlet error:"+e.getMessage());            
        }
        finally
        {
        }
    }
    
    //和POST请求的处理一样
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    	doPost(request,response);
    }
    
	//处理数据
    private String getStrSQL(String a1,String a2,String a3)
    {
    	strSQL="";
		if(!a1.equals(""))
		{
			strSQL=strSQL+" where studentid='"+a1+"'";
			if(!a2.equals("")) strSQL=strSQL+" and thing='"+a2+"'";
			if(!a3.equals("")) strSQL=strSQL+" and outtime like '%"+a3+"%';";
		}else{
			if(!a2.equals(""))
			{
				strSQL=strSQL+" where thing='"+a2+"'";
				if(!a3.equals("")) strSQL=strSQL+" and outtime like '%"+a3+"%';";
			}else{
				if(!a3.equals("")) strSQL=strSQL+" where outtime like '%"+a3+"%';";  
			}
		}	
		strSQL=strSQL+";";
		return strSQL;
    }
    
    //Clean up resources
    public void destroy()
    {
    }
}

⌨️ 快捷键说明

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