dwr更新なし


<%@ page language="java" contentType="text/html; charset=GBK"%>
<html>
	<head>
		 <link rel="stylesheet" type="text/css" href="main.css"/>
		 <script type='text/javascript' src='/pageDemo/dwr/interface/test.js'></script>
  		 <script type='text/javascript' src='/pageDemo/dwr/engine.js'></script>
		 <script type='text/javascript' src='/pageDemo/dwr/util.js'></script>
		 <script type="text/javascript" src="main.js"></script>
		 <script type="text/javascript">
			var nowPage;
			var mmmmmmm;
			function getInfo()
			{
				test.defaultAll(hallnpsot);
			}
			
			function goSelect(selectPageSize)
			{
				var dxsize = mmmmmmm.infoCount;
				if(selectPageSize>dxsize)
				{
					selectPageSize = mmmmmmm.infoCount;
				}
				test.caonimamPageSize(selectPageSize,hallnpsot);
			}
			
			function goupPage()
			{
				
				nowPage = mmm.nowPage;
				nowPage--;
				if(nowPage<=0)
				{
					document.getElementById("message").innerHTML = "   ,      ";
				}else
				{
					test.goup(nowPage,mmmmmmm.pageCount,mmmmmmm.pageSize,hallnpsot);
					document.getElementById("message").innerHTML = "";
				}
			}
			
			function nextPage()
			{
				nowPage = mmm.nowPage;
				nowPage++;
				if(nowPage>mmm.pageCount)
				{
					document.getElementById("message").innerHTML = "   ,       ";
				}else
				{
					test.next(nowPage,mmmmmmm.pageCount,mmmmmmm.pageSize,hallnpsot);
					document.getElementById("message").innerHTML = "";
				}
			}
			
			function goPage()
			{
				var nowPage = document.getElementById("initValue").value;
				if(nowPage=="")
				{
					document.getElementById("message").innerHTML = "   ,        ";
				}else
				{
					test.gotoPage(nowPage,mmmmmmm.pageCount,mmmmmmm.pageSize,hallnpsot);
					document.getElementById("message").innerHTML = "";
				}
			}
			
			function hallnpsot(infoList)
			{
				//alert(infoList);
				var deptInfo = infoList[0];
				mmmmmmm = infoList[1];
				mmm = infoList[1];
				$(selectElement).options[0].value =mmmmmmm.infoCount;
				document.getElementById("msg").innerHTML = "<font color='red'> "+mmm.infoCount+" /  "+mmm.pageSize+"   "+mmm.pageCount+"     "+mmm.nowPage+" </font>";
				//      
				var table = document.getElementById("tableInfo");
				//       
				while(table.rows.length>0)
	        	{
	        	  	table.deleteRow(0);
	        	}
	        	
				//       
				var newTh = table.insertRow();
				
				newTh.style.backgroundColor="#C8ECEC";
				newTh.align="center";
				
				//  TD
				var newTh1 = newTh.insertCell();
				var newTh2 = newTh.insertCell();
				var newTh3 = newTh.insertCell();
				var newTh4 = newTh.insertCell();
				var newTh5 = newTh.insertCell();
				var newTh6 = newTh.insertCell();
				var newTh7 = newTh.insertCell();
				newTh1.style.width="100";
				newTh2.style.width="130";
				newTh3.style.width="190";
				newTh4.style.width="190";
				newTh5.style.width="190";
				newTh6.style.width="60";
				newTh7.style.width="60";
				newTh.className = "style2";
				
				//      
				newTh1.innerHTML = "    ";
				newTh2.innerHTML = "    ";
				newTh3.innerHTML = "    ";
				newTh4.innerHTML = "    ";
				newTh5.innerHTML = "    ";
				newTh6.innerHTML = "  ";
				newTh7.innerHTML = "  ";
				
				
				for(var i=0;i<deptInfo.length;i++)
				{
					//         
					var id = deptInfo[i].id;
					var name = deptInfo[i].name;
					var email = deptInfo[i].email;
					var tel = deptInfo[i].tel;
					var address = deptInfo[i].address;
					//    
					var newTr = table.insertRow();
					newTr.style.backgroundColor="#E6E6E6";
					newTr.align="center";
					newTr.className = "style3";
					
					//  5 
					var newTd1 = newTr.insertCell();
					var newTd2 = newTr.insertCell();
					var newTd3 = newTr.insertCell();
					var newTd4 = newTr.insertCell();
					var newTd5 = newTr.insertCell();
					var newTd6 = newTr.insertCell();
					var newTd7 = newTr.insertCell();
					//        
					newTd1.innerHTML = id;
					newTd2.innerHTML = name;
					newTd3.innerHTML = email;
					newTd4.innerHTML = tel;
					newTd5.innerHTML = address;
					newTd6.innerHTML = "<a href='javascript:void(0)' onclick=''>  </a>";
					newTd7.innerHTML = "<a href='javascript:void(0)' onclick=''>  </a>";
				}
			}
		</script>
	</head>
  <body onload="getInfo()">
  		<center>
  			<div class="style1" id="message"></div>
  			<table id="tableInfo" width="800" border="0" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC"></table>
  			<table border="0" width="800">
  				<tr align="left">
  					<td align="left" id="msg" width="250"><br>
  						
  					<br></td>
  					<td width="150">
  						<a href="javascript:void(0)" onclick="goupPage()">   </a>
  						  
  						<a href="javascript:void(0)" onclick="nextPage()">   </a>
  					</td>
  					<td align="left" width="80">
  						<input type="text" id="initValue" size="5"/>
  						<input type="button" id="gonum" value="GO" onclick="goPage()"/>
  					</td>
  					<td>
  						    :
  						<select id="selectElement" onchange="goSelect(this.value)">
  							<option value="">  </option>
  							<option value="5">5</option>
  							<option value="10">10</option>
  							<option value="15">15</option>
  							<option value="20">20</option>
  							<option value="50">50</option>
  							<option value="100">100</option>
  						</select>
  					</td>
  				</tr>
  			</table>
  		</center>
  </body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!--   DWR Servlet -->
  <servlet>
	<servlet-name>dwr-invoker</servlet-name>
	<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
	<init-param>
		<param-name>debug</param-name>
		<param-value>true</param-value>
	</init-param>
  </servlet>
  <servlet-mapping>
		<servlet-name>dwr-invoker</servlet-name>
		<url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
</web-app>
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting
2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd" >
<!-- <!DOCTYPE dwr SYSTEM "dwr20.dtd" > -->
<dwr>
   <allow>
   		<create creator="new" javascript="test">
   			<param name="class" value="taotao.montao.service.ServiceMethod"/>
   			<include method="defaultAll"/>
   			<include method="next"/>
   			<include method="goup"/>
   			<include method="gotoPage"/>
   			<include method="caonimamPageSize"/>
   		</create>
   		<convert converter="bean" match="taotao.montao.vo.DeptVO">
   			<param name="include" value="id,name,email,tel,address"/>
   		</convert>
   		
   		<convert converter="bean" match="taotao.montao.vo.PageVO">
   			<param name="include" value="pageCount,nowPage,pageSize,infoCount"/>
   		</convert>
   </allow>
</dwr>
package taotao.montao.service;

import java.util.List;

import taotoa.montao.dao.TestDAO;

public class ServiceMethod {
	
	TestDAO dao = new TestDAO();
	
	//GO  
	@SuppressWarnings("unchecked")
	public List gotoPage(int nowpager,int pageContent,int pageSizeSize)
	{
		return dao.gotoPage(nowpager,pageContent,pageSizeSize);
	}
	
	//        
	@SuppressWarnings("unchecked")
	public List caonimamPageSize(int pagePageSize)
	{
		return dao.setSize(pagePageSize);
	}
	
	//         
	@SuppressWarnings("unchecked")
	public List defaultAll()
	{
		return dao.defaultInfo();
	}
	
	//      
	@SuppressWarnings("unchecked")
	public List next(int nowpager,int pageContent,int pageSizeSize)
	{
		return dao.nextInfo(nowpager,pageContent,pageSizeSize);
	}
	
	//      
	@SuppressWarnings("unchecked")
	public List goup(int nowpager,int pageContent,int pageSizeSize)
	{
		return dao.goupInfo(nowpager,pageContent,pageSizeSize);
	}
}
package taotoa.montao.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import taotao.montao.dbcon.DBCon;
import taotao.montao.vo.DeptVO;
import taotao.montao.vo.PageVO;

public class TestDAO {
	
	private DBCon db = null;
	private PageVO page = new PageVO();
	
	//       
	public int getInfoCount()
	{
		int infoCount = 0;
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		//  SQL  
		String strSql = "select * from dept";
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				infoCount++;
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return infoCount;
	}
	
	@SuppressWarnings("unchecked")
	public List goupInfo(int nowpager,int pageContent,int pageSizeSize)
	{
		this.defaultInfo();
		page.setNowPage(nowpager);
		page.setPageSize(pageSizeSize);
		page.setPageCount(pageContent);
		List mmm = new ArrayList();
		if(nowpager<=0)
		{
			page.setNowPage(1);
		}
		
		int startLine = (page.getNowPage()*page.getPageSize())-page.getPageSize(); //     
		
		System.out.println("     : "+startLine);
		
		//        
		List<DeptVO> list = new ArrayList<DeptVO>();
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		//  SQL  
		String strSql = "select * from dept limit "+startLine+","+page.getPageSize();
		System.out.println(strSql);
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				DeptVO dept = new DeptVO();
				dept.setId(rs.getInt("id"));
				dept.setName(rs.getString("name"));
				dept.setEmail(rs.getString("email"));
				dept.setTel(rs.getString("tel"));
				dept.setAddress(rs.getString("address"));
				list.add(dept);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		mmm.add(0,list);
		mmm.add(1,page);
		return mmm;
	}
	
	@SuppressWarnings("unchecked")
	public List setSize(int pagePageSize)
	{
		this.defaultInfo();
		page.setPageSize(pagePageSize);
		if(pagePageSize>=page.getInfoCount())
		{
			page.setPageCount(page.getInfoCount()/page.getPageSize());
		}else
		{
			page.setPageCount(page.getInfoCount()/page.getPageSize()+1);
		}
		System.out.println("    : "+page.getPageCount());
		List mmm = new ArrayList();
		//        
		List<DeptVO> list = new ArrayList<DeptVO>();
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		System.out.println(page.getPageSize());
		//  SQL  
		String strSql = "select * from dept limit 0,"+(page.getPageSize());
		System.out.println(strSql);
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				DeptVO dept = new DeptVO();
				dept.setId(rs.getInt("id"));
				dept.setName(rs.getString("name"));
				dept.setEmail(rs.getString("email"));
				dept.setTel(rs.getString("tel"));
				dept.setAddress(rs.getString("address"));
				list.add(dept);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		mmm.add(0,list);
		mmm.add(1,page);
		return mmm;
	}
	
	@SuppressWarnings("unchecked")
	public List gotoPage(int nowpager,int pageContent,int pageSizeSize)
	{
		this.defaultInfo();
		page.setNowPage(nowpager);
		page.setPageSize(pageSizeSize);
		page.setPageCount(pageContent);
		List mmm = new ArrayList();
		if(nowpager>page.getPageCount())
		{
			page.setNowPage(page.getPageCount());  //            
		}
		int startLine = page.getNowPage()*page.getPageSize()-page.getPageSize(); //     
		
		//        
		List<DeptVO> list = new ArrayList<DeptVO>();
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		//  SQL  
		String strSql = "select * from dept limit "+startLine+","+page.getPageSize();
		System.out.println(strSql);
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				DeptVO dept = new DeptVO();
				dept.setId(rs.getInt("id"));
				dept.setName(rs.getString("name"));
				dept.setEmail(rs.getString("email"));
				dept.setTel(rs.getString("tel"));
				dept.setAddress(rs.getString("address"));
				list.add(dept);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		mmm.add(0,list);
		mmm.add(1,page);
		return mmm;
	}
	
	@SuppressWarnings("unchecked")
	public List nextInfo(int nowpager,int pageContent,int pageSizeSize)
	{
		this.defaultInfo();
		page.setNowPage(nowpager);
		page.setPageSize(pageSizeSize);
		page.setPageCount(pageContent);
		List mmm = new ArrayList();
		if(nowpager>page.getPageCount())
		{
			page.setNowPage(page.getPageCount());  //            
		}
		int startLine = (page.getNowPage()-1)*page.getPageSize(); //     
		
		//        
		List<DeptVO> list = new ArrayList<DeptVO>();
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		//  SQL  
		String strSql = "select * from dept limit "+startLine+","+page.getPageSize();
		System.out.println(strSql);
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				DeptVO dept = new DeptVO();
				dept.setId(rs.getInt("id"));
				dept.setName(rs.getString("name"));
				dept.setEmail(rs.getString("email"));
				dept.setTel(rs.getString("tel"));
				dept.setAddress(rs.getString("address"));
				list.add(dept);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		mmm.add(0,list);
		mmm.add(1,page);
		return mmm;
	}

	//         
	@SuppressWarnings("unchecked")
	public List defaultInfo()
	{
		int nowPage = 1;
		if (nowPage < 1)
		{
			nowPage =1; 
		}
		//        
		List<DeptVO> list = new ArrayList<DeptVO>();
		//     
		page.setInfoCount(this.getInfoCount());      //      
		page.setNowPage(nowPage);                    //      
		page.setPageSize(5);                         //       
		page.setPageCount(page.getInfoCount()/page.getPageSize()+1);  //     
		
		//  Connection  
		db = new DBCon();
		Connection conn = db.getConnection();
		//  SQL  
		String strSql = "select * from dept limit 0,"+(page.getPageSize());
		//    
		Statement stmt = null;
		ResultSet rs = null;
		try
		{
			stmt = conn.createStatement();
			rs = stmt.executeQuery(strSql);
			while(rs.next())
			{
				DeptVO dept = new DeptVO();
				dept.setId(rs.getInt("id"));
				dept.setName(rs.getString("name"));
				dept.setEmail(rs.getString("email"));
				dept.setTel(rs.getString("tel"));
				dept.setAddress(rs.getString("address"));
				list.add(dept);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}finally
		{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		List mm = new ArrayList();
		mm.add(0,list);
		mm.add(1,page);
		return mm;
	}
}