`
ding43930053
  • 浏览: 38480 次
社区版块
存档分类
最新评论

最近遇到了分页的问题,以前真的没仔细研究过了,这几天仔细研究了一下和在网上找到了一些资料,基本原理弄清楚了,首先感谢网上那些资料的作者,以下是我的页面代码(包括完成的登录验证和数据分页)如下:

 
阅读更多
首先看一下我WEB.xml吧
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- servlet -->
  <servlet>
  	<servlet-name>LoginServlet</servlet-name>
  	<servlet-class>com.tdb.sevice.controller.LoginServlet</servlet-class>
  </servlet>
  <servlet>
  	<servlet-name>pageServlet</servlet-name>
  	<servlet-class>com.tdb.sevice.controller.PageServlet</servlet-class>
  </servlet>

  <!-- servlet-mapping -->
  <servlet-mapping>
  	<servlet-name>LoginServlet</servlet-name>
  	<url-pattern>/checkLoing</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
  	<servlet-name>pageServlet</servlet-name>
  	<url-pattern>/pageServlet</url-pattern>
  </servlet-mapping>

</web-app>
看一下我的数据库连接工具类吧,连接Ooracle的:

package com.tdb.util;

public class BeansConstants {

	public static final String dbdriver = "oracle.jdbc.driver.OracleDriver";

	public static final String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:tdb";
	public static final String du = "tdb";
	public static final String dp = "tdb";
	public static BeansConstants getInstance() {
		// TODO Auto-generated method stub
		return new BeansConstants();
	}

}


package com.tdb.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement ;
import java.sql.Date;


/**
 * 处理数据库的连接和访问
 * @author sanware bqlr
 * @version 1.01
 */
public class MyOracle {

	private Connection conn = null;
	private Statement stmt = null;
	private PreparedStatement prepstmt = null;

//	这是一个全局类,里面放置数据库的参数,如数据库主机 访问用户名 密码等
	private static BeansConstants CONST = BeansConstants.getInstance();

	/**
	 * 构造数据库的连接和访问类
	 */
	public MyOracle() throws Exception {
		Class.forName(CONST.dbdriver);
		conn = DriverManager.getConnection(CONST.dburl, CONST.du, CONST.dp);
		stmt = conn.createStatement();
	}
	public MyOracle(String sql) throws Exception {
		Class.forName(CONST.dbdriver);
		conn = DriverManager.getConnection(CONST.dburl, CONST.du, CONST.dp);
		this.prepareStatement(sql);
	}

	/**
	 * 返回连接
	 * @return Connection 连接
	 */
	public Connection getConnection() {
		return conn;
	}
	/**
	 * PreparedStatement
	 * @return sql 预设SQL语句
	 */
	public void prepareStatement(String sql) throws SQLException {
		prepstmt = conn.prepareStatement(sql);
	}
	/**
	 * 设置对应值
	 * @param index 参数索引
	 * @param value 对应值
	 */
	public void setString(int index,String value) throws SQLException {
		prepstmt.setString(index,value);
	}
	public void setInt(int index,int value) throws SQLException {
		prepstmt.setInt(index,value);
	}
	public void setBoolean(int index,boolean value) throws SQLException {
		prepstmt.setBoolean(index,value);
	}
	public void setDate(int index,Date value) throws SQLException {
		prepstmt.setDate(index,value);
	}
	public void setLong(int index,long value) throws SQLException {
		prepstmt.setLong(index,value);
	}
	public void setFloat(int index,float value) throws SQLException {
		prepstmt.setFloat(index,value);
	}
//	File file = new File("test/data.txt");
//	int fileLength = file.length();
//	InputStream fin = new java.io.FileInputStream(file);
//	mysql.setBinaryStream(5,fin,fileLength);
	public void setBinaryStream(int index,InputStream in,int length) throws SQLException {
		prepstmt.setBinaryStream(index,in,length);
	}

	public void clearParameters()
	throws SQLException
	{
		prepstmt.clearParameters();
	}
	/**
	 * 返回预设状态
	 */
	public PreparedStatement getPreparedStatement() {
		return prepstmt;
	}
	

	/**
	 * 返回状态
	 * @return Statement 状态
	 */
	public Statement getStatement() {
		return stmt;
	}
	/**
	 * 执行SQL语句返回字段集
	 * @param sql SQL语句
	 * @return ResultSet 字段集
	 */
	public ResultSet executeQuery(String sql) throws SQLException {
		if (stmt != null) {
			return stmt.executeQuery(sql);
		}
		else return null;
	}
	public ResultSet executeQuery() throws SQLException {
		if (prepstmt != null) {
			return prepstmt.executeQuery();
		}
		else return null;
	}
	/**
	 * 执行SQL语句
	 * @param sql SQL语句
	 */
	public void executeUpdate(String sql) throws SQLException {
		if (stmt != null)
			stmt.executeUpdate(sql);
	}
	public void executeUpdate() throws SQLException {
		if (prepstmt != null)
			prepstmt.executeUpdate();
	}
	/**
	 * 关闭连接
	 */
	public void close() throws Exception {
		if (stmt != null) {
			stmt.close();
			stmt = null;
		}
		if (prepstmt != null) {
			prepstmt.close();
			prepstmt = null;
		}
		conn.close();
		conn = null;
	}
}



接下来看一下我的登录页面吧index.jsp,前台没有做任何验证,其实正常的开发需要在前台做验证,比如说是否为空,脚本可以用(javascript....)

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<% 
	/*如果登录信息错误,获取从servlet传过来的错误信息,并且显示出来,然后return*/
	String error = (String)session.getAttribute("error");
	if(error != null && !error.trim().equals("")){
		error = (String)session.getAttribute("error");
	}else {
		error = "";
	}
%>
<style type="text/css">
body {
	margin:0;
}
</style>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>设备现场图片检验系统</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    
  <div align="center">
  <!-- 提交到servlet -->
  <form action="checkLoing" method="post">
    <table width="1024" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="341" height="148"></td>
        <td width="427"></td>
        <td width="256"></td>
      </tr>
	
      <tr>
        <td height="137"></td>
        <td valign="top">
		
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="427" height="47" align="left" valign="middle">设备现场图片检验系统</td>
          </tr>
        
        	<p><%= error %></p>
          <tr>
            <td height="30" align="left" valign="middle">户 名:
              <input type="text" name="username"></td>
          </tr>
          <tr>
            <td height="30" align="left" valign="middle">密 码:
              <input type="password" name="password"></td>
          </tr>
          <tr>
          					
            <td height="30" valign="top"><input type="submit" name="submit" value="登录到设备检测系统"/></td>
          </tr>
		
        </table></td>
       
        <td></td>
      </tr>
      
      <tr>
        <td height="115"></td>
        <td></td>
        <td></td>
      </tr>
    </table>
        </form>
  </div>
  </body>

</html>


接下来看一下我的登录验证Servlet吧(LoginServlet):

package com.tdb.sevice.controller;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tdb.sevice.model.LoginUserBean;
import com.tdb.util.MyOracle;


public class LoginServlet extends HttpServlet{

	/**
	 * 判断登录用户是否存在
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	public void CheckLoing(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {
//		TODO Auto-generated method stub
		String username = req.getParameter("username");
		String password = req.getParameter("password");

		if((username != null && !username.trim().equals("")) && (password != null && !password.trim().equals(""))){
			username = req.getParameter("username");
			password = req.getParameter("password");
			HttpSession session = req.getSession(true);
			
			MyOracle myoracle = null;
			try {

				myoracle = new MyOracle("select count(*) from loginuse where usern=? and passw=?");
				myoracle.setString(1, username);
				myoracle.setString(2, password);
				ResultSet rs = myoracle.executeQuery();
				rs.next();
				if(rs.getInt(1) <= 0){
					System.out.println("密码输入错误");
					session.setAttribute("error", "用户名或密码错误");
					resp.sendRedirect("index.jsp");
				}else {
					System.out.println("密码输入成功");
					LoginUserBean loginUser = new LoginUserBean();
					loginUser.setUsern(username);
					loginUser.setPassw(password);
					session.setAttribute("loginUser", loginUser);
					resp.sendRedirect("pageServlet");

				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				try {
					myoracle.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}else {
			username = " ";
			password = " ";
			resp.sendRedirect("index.jsp");
		}
	}

	
		
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}	
		
	@Override

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		CheckLoing(req, resp);
		
		
	}
	
}

看一下我的登录用户的模型:

package com.tdb.sevice.model;

/**
 * 
 * @author Administrator
 * 登录用户的数据模型
 */
public class LoginUserBean {

	private int useNo;
	
	private String usern;
	
	private String passw;

	public int getUseNo() {
		return useNo;
	}

	public void setUseNo(int useNo) {
		this.useNo = useNo;
	}

	public String getUsern() {
		return usern;
	}

	public void setUsern(String usern) {
		this.usern = usern;
	}

	public String getPassw() {
		return passw;
	}

	public void setPassw(String passw) {
		this.passw = passw;
	}
	
	
}


那么成功登录了,然后转到分页的Servlet,看一下我的PageServlet吧

package com.tdb.sevice.controller;


import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tdb.sevice.model.ContactBean;
import com.tdb.sevice.model.PageBean;

public class PageServlet extends javax.servlet.http.HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws javax.servlet.ServletException, java.io.IOException {
		response.setContentType("text/html");
		try {
			PageBean pagebean = new PageBean();
			ContactBean contact = new ContactBean();
			System.out.println("servlet测试点1");
			int pagecount = pagebean.countPage();//获取总共的页数
			System.out.println("servlet测试点2"+pagecount);
			String topage = request.getParameter("topage");//获取当前的页码
			System.out.println("servlet测试点3"+topage);
			
			
			if(topage != null && !topage.trim().equals("")){
				if (Integer.parseInt(topage) > pagecount) {  //判断当前的页码是否越界,如果是的话就进行处理
					topage =String.valueOf(pagecount);
					System.out.println("servlet测试点4"+topage);
				} else if (Integer.parseInt(topage) <= 0) {
					topage = "1";
					System.out.println("servlet测试点5"+topage);
				}
			}else {
				topage = "1";
				System.out.println("servlet测试点6"+topage);
			}
			
			
		
			
			ArrayList devicebase = contact.getData(topage, pagecount);
			request.getSession().setAttribute("pagecount", pagecount);
			request.getSession().setAttribute("topage", topage);//将当前的页码返回给页面,这样进行计算
			request.getSession().setAttribute("devicebase", devicebase);
			response.sendRedirect("main.jsp");
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)

	throws javax.servlet.ServletException, java.io.IOException {
		doGet(request, response);
	}
}


看一下Bean类吧

首先是页面数据模型PageBean:

package com.tdb.sevice.model;


public class PageBean {

	public int maxPage; // 一共有多少页
	public int maxRowCount; // 一共有多少行
	public static final int pagesize = 15; // 每页多少行
	public PageBean() {

	}

	public int countPage() throws Exception {
		
		int maxRowCount=this.MaxCount();
		System.out.println("MaxCount="+maxRowCount);
		if (maxRowCount % this.pagesize == 0) {
			maxPage = maxRowCount / this.pagesize;
		} else {
			maxPage =maxRowCount/ this.pagesize + 1;
		}
		return maxPage;
	}


	public int MaxCount() throws Exception {
		ContactBean contact=new ContactBean();
		this.maxRowCount = contact.getAvailableCount(); // 得到总行数
		return maxRowCount;
	}

}


接下来的是页面和数据之间需要架起一座小桥,这个小桥就是我的页面到数据库的联系模型ContactBean:

package com.tdb.sevice.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;

import com.tdb.sevice.model.PageBean;
import com.tdb.util.MyOracle;

public class ContactBean {
	/*获取连接数据库工具*/
	private MyOracle myOracle ;
	
	/** *返回要查询的记录数 */
	public int getAvailableCount() throws Exception {
		int ret = 0;
		String strSql = "select count(*) from devicebase";
		myOracle = new MyOracle();
		ResultSet rset = myOracle.executeQuery(strSql);
		while (rset.next()) {
			ret = rset.getInt(1);
		}
		myOracle.close();
		return ret;
	}

	/*获取查寻的记录数*/
	public ArrayList getData(String topage, int pagecount)
	throws Exception {
		myOracle = new MyOracle();
		int pagesize = PageBean.pagesize;
		/*计算查询数据的起始值*/
		int pageStart = (Integer.parseInt(topage) - 1) * pagesize;
		
		/*计算查询数据的结束值*/
		int pageEnd = pageStart + pagesize;
		
		myOracle = new MyOracle();
		String sql = "SELECT * FROM devicebase WHERE ROWNUM<=" + pageEnd + " minus SELECT * FROM devicebase WHERE ROWNUM<="+pageStart;;
		ResultSet rs = myOracle.executeQuery(sql);
		ArrayList list = new ArrayList();
		int j=0;
		while(rs.next()){
			DeviceBean device = new DeviceBean();   
			device.setDeviceNo(rs.getString(1));   
			device.setDeviceModel(rs.getString(2));
			device.setDeviceScope(rs.getString(3));
			device.setDeviceAddress(rs.getString(4));
			device.setRadminUserName(rs.getString(5));
			device.setRadminPass(rs.getString(6));
			device.setRadminAddress(rs.getString(7));
			list.add(j, device);
			++j;
		}
		myOracle.close();
		return list;
	}
}


还有我的基础数据Model,DeviceBean:

package com.tdb.sevice.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.tdb.util.MyOracle;

public class DeviceBean {
	
	private String deviceNo;
	private String deviceModel;
	private String deviceScope;
	private String deviceAddress;
	private String radminUserName;
	private String radminPass;
	private String radminAddress;
	
	
	public String getDeviceNo() {
		return deviceNo;
	}
	public void setDeviceNo(String deviceNo) {
		this.deviceNo = deviceNo;
	}
	public String getDeviceModel() {
		return deviceModel;
	}
	public void setDeviceModel(String deviceModel) {
		this.deviceModel = deviceModel;
	}
	public String getDeviceScope() {
		return deviceScope;
	}
	public void setDeviceScope(String deviceScope) {
		this.deviceScope = deviceScope;
	}
	public String getDeviceAddress() {
		return deviceAddress;
	}
	public void setDeviceAddress(String deviceAddress) {
		this.deviceAddress = deviceAddress;
	}
	public String getRadminUserName() {
		return radminUserName;
	}
	public void setRadminUserName(String radminUserName) {
		this.radminUserName = radminUserName;
	}
	public String getRadminPass() {
		return radminPass;
	}
	public void setRadminPass(String radminPass) {
		this.radminPass = radminPass;
	}
	public String getRadminAddress() {
		return radminAddress;
	}
	public void setRadminAddress(String radminAddress) {
		this.radminAddress = radminAddress;
	}
	
	
	
	
	private String deviceBase_insert="insert into deviceBase values (?,?,?,?,?,?,?)";
	
	public void insertnavlink() throws Exception
	{
		try{
			ResultSet rs=null;
			MyOracle myoracle = new MyOracle(deviceBase_insert);
			myoracle.setString(1, this.deviceNo);
			myoracle.setString(2, this.deviceModel);
			myoracle.setString(3, this.deviceScope);
			myoracle.setString(4, this.deviceAddress);
			myoracle.setString(5, this.radminUserName);
			myoracle.setString(6, this.radminPass);
			myoracle.setString(7, this.radminAddress);
			myoracle.executeUpdate();
			myoracle.close();

		

		} catch (Exception ex) {
			throw new Exception("insertnavlink()"+ex.getMessage());
		}
	}
	
	/**
	 * 根据编号查询设备基本信息
	 */
	private String deviceBase_select="select * from devicebase where deviceNo = ?";
	public DeviceBean getParmslink() throws Exception
	{
		DeviceBean db = null;
		try{
			ResultSet rs=null;
			MyOracle myoracle = new MyOracle();
			rs = myoracle.executeQuery(deviceBase_select);
			db = new DeviceBean();
			while(rs.next()){
				db.setDeviceNo(rs.getString(1));
				db.setDeviceModel(rs.getString(2));
				db.setDeviceScope(rs.getString(3));
				db.setDeviceAddress(rs.getString(4));
				db.setRadminUserName(rs.getString(5));
				db.setRadminPass(rs.getString(6));
				db.setRadminAddress(rs.getString(7));
			}
			myoracle.close();

		} catch (Exception ex) {
			throw new Exception("getParmslink()"+ex.getMessage());
		}
		return db;
	}
	
	/**
	 * 分页程序
	 * 查询所有的设备基本信息
	 * return ArrayList
	 */
	
	public <DeviceBase>ArrayList getListParmslink(int start, int end) throws Exception
	{
		String getListParms_select ="SELECT * FROM devicebase WHERE ROWNUM<=" + end + " minus SELECT * FROM devicebase WHERE ROWNUM<="+start;
		ArrayList al = null;
		try{
			
			MyOracle myoracle = new MyOracle();
			ResultSet rs = myoracle.executeQuery(getListParms_select);
			//System.out.println("测点一");
			al = new ArrayList();
			//System.out.println("测点二");
			while(rs.next()){
				//System.out.println("测点三");
				DeviceBean db = new DeviceBean();
			//	System.out.println("测点四");
				db.setDeviceNo(rs.getString(1));
				db.setDeviceModel(rs.getString(2));
				db.setDeviceScope(rs.getString(3));
				db.setDeviceAddress(rs.getString(4));
				db.setRadminUserName(rs.getString(5));
				db.setRadminPass(rs.getString(6));
				db.setRadminAddress(rs.getString(7));
				al.add(db);
			}
			myoracle.close();

		} catch (Exception ex) {
			throw new Exception("getListParmslink()"+ex.getMessage());
		}
		return al;
	}
	
	
	String pageSizeSelect = "select count(*) from devicebase";
	public int getPageSize(){
		MyOracle myoracle;
		ResultSet rs ;
		int pageSize = 0;
	
			try {
				myoracle = new MyOracle();
				rs = myoracle.executeQuery(pageSizeSelect);
				rs.next();
				pageSize = rs.getInt(1);
				System.out.println(pageSize);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return pageSize;
			
	}
		
	
	/**
	 * 测试数据
	 * @param args
	 */
	public static void main(String []args){
		DeviceBean db = new DeviceBean();
		try {
			for(int i=2; i<103; i++){
				db.setDeviceNo("Ae-00"+i);
				db.setDeviceModel("TFDS-30"+i);
				db.setDeviceScope("长北上行");
				db.setDeviceAddress("苏家屯");
				db.setRadminUserName("TF");
				db.setRadminPass("tf123456");
				db.setRadminAddress("192.168.255.255");
				db.insertnavlink();
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


最后看一下我JSP分页的页面吧:

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="java.util.*" %>
<%@ page import="com.tdb.sevice.model.*" %>
<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%


LoginUserBean loginUser = (LoginUserBean)session.getAttribute("loginUser");

if(loginUser == null){
out.println("<html><body>");
out.println("<p><a href='index.jsp'>请先登录,返回到登录页面</a></p>");
out.println("</body></html>");
return;
}else {
loginUser = (LoginUserBean)session.getAttribute("loginUser");
}
/*登录退出,使之session失效*/
String sessionClose = request.getParameter("quit");
if(sessionClose != null && sessionClose.trim().equals("quit")){
session.invalidate();
response.sendRedirect("index.jsp");
System.out.println("ffffffffffff");
}


%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>Home Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="mm_spa.css" type="text/css" />
<style type="text/css">
<!--
.STYLE5 {
font-size: 11pt;
font-family: "宋体";
}
-->
</style>
</head>
<style type="text/css">
.STYLE2 {color: #006699}
.STYLE3 {
line-height:16px; letter-spacing:.1em; text-decoration: none;
font: 11px Georgia, Times New Roman, Times, serif;
}
#mdA table,#mdA table td,#mdA table th{
border:1px solid #006699;
border-collapse:collapse;
}

thead {
background:#CCCCCC
}


#myhref A:link,A:visited ,A:active{
TEXT-DECORATION: none



}

</style>
<body bgcolor="#FFFFFF">
<table border="0" cellspacing="0" cellpadding="0">
<!--DWLayoutTable-->
<tr>

<td height="14" colspan="4" align="right" valign="top">当前用户:<%= loginUser.getUsern() %>&nbsp;&nbsp;<a href="main.jsp?quit=quit">退出</a></td>
</tr>
<tr bgcolor="#006699">
<td colspan="3" rowspan="2" valign="top" nowrap="nowrap"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td width="100%" height="55" valign="bottom" nowrap="nowrap" id="logo">铁道部设备现场图片检测系统<br /></td>
<td width="7" rowspan="2">&nbsp;</td>
</tr>

<tr bgcolor="#006699">
<td height="33" valign="top" nowrap="nowrap" id="tagline">哈尔滨科佳机电通用有限公司</td>
</tr>
<tr bgcolor="#006699">
<td height="21" colspan="5" valign="top" bgcolor="#CCCCCC"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>

<tr>
<td height="255" colspan="2" valign="top" id="navborder"><br />
<table border="0" cellspacing="0" cellpadding="0" width="160" id="navigation">
<tr>
<td width="160"><a href="javascript:;" class="navText"><span class="STYLE2">基本信息</span><br />
</a></td>
</tr>
<tr>
<td width="160"><a href="javascript:;" class="STYLE3"><span class="STYLE2">图片浏览</span><br />
</a></td>
</tr>
<tr>
<td width="160"><a href="javascript:;" class="navText"><span class="STYLE2">故障图片</span><br />
</a></td>
</tr>
<tr>
<td width="160"><a href="javascript:;" class="navText"><span class="STYLE2">???</span>g<br />
</a></td>
</tr>
<tr>
<td width="160"><a href="javascript:;" class="navText"><span class="STYLE2">????</span><br />
</a></td>
</tr>
</table> </td>
<td width="45">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="917" height="179" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="826" height="14">&nbsp;</td>
</tr>
<tr>
<td height="165" align="left" valign="baseline"><div class="title">
<h1 class="STYLE5"><span class="STYLE5">基本信息</span></h1>
</div>
<div id="mdA">
<table width="100%" id="mytab" class="t1" border="0">
<!--DWLayoutTable-->
<thead>
<tr>
<th width="78" height="18" align="left" valign="middle">设备编号</th>
<th width="78" align="left" valign="middle">型号</th>
<th width="78" align="left" valign="top">探测站</th>
<th width="78" align="left" valign="middle">测点名称</th>
<th width="78" align="left" valign="middle">radmin用户</th>
<th width="98" align="left" valign="middle">radmin密码</th>
<th width="98" align="left" valign="middle">radmin地址</th>
<th width="295" align="left" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</th>
</thead>





<jsp:useBean id="devicebase" type="java.util.ArrayList" scope="session"/>

<%
for(Iterator it=devicebase.iterator();it.hasNext();){
DeviceBean device = (DeviceBean)it.next();

%>
<tr class="a1" onmouseover="this.bgColor='#E1E1E1';" onmouseout="this.bgColor='#FFFFFF';">


<td height="24" align="left" valign="middle"><%= device.getDeviceNo() %></td>
<td align="left" valign="middle"><%= device.getDeviceModel() %> </td>
<td align="left" valign="middle"><%= device.getDeviceScope() %> </td>
<td align="left" valign="middle"><%= device.getDeviceAddress() %> </td>
<td align="left" valign="middle"><%= device.getRadminUserName() %> </td>
<td align="left" valign="middle"><%= device.getRadminPass() %></td>
<td align="left" valign="middle"><%= device.getRadminAddress() %></td>

<td align="left" valign="middle"><form id="form1" name="form1" method="post" action="">
<label>
<input type="submit" name="submit" value="删 除" />
&nbsp; &nbsp;
<input type="submit" name="submit" value="修 改" />
</label>
</form></td>
</tr>
<%
}
%>
</table>
</div> </td>
</tr>
</table> </td>
</tr>
<tr>
<td height="76" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="61" height="40">&nbsp;</td>
<td width="61">&nbsp;</td>
<td width="61">&nbsp;</td>
<td width="61">&nbsp;</td>
<td width="61">&nbsp;</td>
<td width="132">&nbsp;</td>
<td width="558">&nbsp;</td>
</tr>
<tr>
<td height="39" align="left" valign="middle"><form id="form2" name="form2" method="post" action="deviceInsert.jsp">
<label>
<input type="submit" name="Submit" value="新 增" />
</label>
</form>
<td align="left" valign="middle"><form id="form2" name="form2" method="post" action="pageServlet">
<label>
<input type="submit" name="Submit" value="首 页"/>
<input type="hidden" name="topage" value="1" />
</label>
</form></td>
<td align="left" valign="middle"><form id="form2" name="form2" method="post" action="pageServlet">
<label>
<input type="submit" name="Submit" value="下一页" />
<input type="hidden" name="topage" value="<%= String.valueOf(Integer.parseInt((String)request.getSession().getAttribute("topage"))+1) %>" />
</label>
</form></td>
<td align="left" valign="middle"><form id="form2" name="form2" method="post" action="pageServlet">
<label>
<input type="submit" name="Submit" value="上一页" />
<input type="hidden" name="topage" value="<%= String.valueOf(Integer.parseInt((String)request.getSession().getAttribute("topage"))-1) %>" />
</label>
</form></td>
<td align="left" valign="middle"><form id="form2" name="form2" method="post" action="pageServlet">
<label>
<input type="submit" name="Submit" value="尾 页" />
<input type="hidden" name="topage" value="<%= request.getSession().getAttribute("pagecount") %>" />
</label>
</form></td>
<td align="left" valign="middle">第<%= request.getSession().getAttribute("topage") %>页,共<%= request.getSession().getAttribute("pagecount") %>页</td>
<td>&nbsp;</td>
</tr>


</table> </td>
</tr>
</table> </td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="88" height="14">&nbsp;</td>
<td colspan="4" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="49" height="47">&nbsp;</td>
<td width="982" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="982" height="24" align="center" valign="middle"></td>
</tr>
<tr>
<td height="23" align="center" valign="middle"></td>
</tr>
<tr>
<td height="23" align="center" valign="middle"> </tr>
</table> </td>
<td width="59">&nbsp;</td>
</tr>
</table> </td>
</tr>
<tr>
<td height="1"></td>
<td width="72"></td>
<td></td>
<td></td>
<td><br /><br /></td>
</tr>
</table>
</body>

</html>

好了整体的架构流程我给大家介绍一下:

首先进入登录页面,需要通过LoginServlet 做用户名和密码验证,如果成功,传递一个用户的sesson , 每个页面会做验证如果页面没有获取到用户的session会提示转到登录页面,如果成功登录,LoginServlet使用resp.sendRedirect("pageServlet");重定向到pageServlet这个类里面来,pageServlet 调用ContactBean来获取到一个装满我的基础类DeviceBean的一个ArrayList类并且使用session传递到main.jsp页面,当然还调用ContactBean来获取int pagecount = pagebean.countPage();//获取总共的页数,然后通过重定向到main.jsp,main.jsp,每次翻页的时候都action到pageServlet,好了这就是我登录到数据分页采用MVC模式三层架构(JSP+servlet+Bean)的研究结果。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics