当前位置:编程学习 > JSP >>

Oracle & JSP 开发的小型信息管理系统 (三) 源代码2

答案:
//articleconn.jsp 数据库连接文件,几乎被每个页面包含,有的页面去掉获得Session,修改一下这个代码,很简单

<%@ page contentType="text/html;charset=big5"%><%@ page import="java.sql.*"%>

  <%       request.setCharacterEncoding("big5");  Connection conn=null;  Statement stmt=null;  try{  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  String url="jdbc:oracle:thin:@192.168.56.199:1521:asdb";  String user="system";  String password="oracle01";  conn=DriverManager.getConnection(url, user, password);  }  catch(Exception e1){  e1.printStackTrace();}    %>

//************************************manage.jsp管理页面,提供分页,修改,删除,添加的链接

<%/*Cookie cookies[]=request.getCookies();if(cookies==null){ response.sendRedirect("login.jsp"); }String userName=(String)session.getAttribute("admin");out.println("Welcome, "+userName);if(userName==null){response.sendRedirect("login.jsp");}*/%><%@ include file="articleconn.jsp"%><html>

<head><meta http-equiv="Content-Type" content="text/html; charset=big5"><title>管理文件</title><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><link rel="stylesheet" href=>
<%request.setCharacterEncoding("big5");String query=" Select * "+             " from learning order by article_id ";String title=null;            String queryCount=" select count(*)from learning  ";String strPage=request.getParameter("strPage");int intPage;if(strPage==null){intPage=1;}else{intPage=Integer.parseInt(strPage);}

int pageSizes=10;//每頁顯示信息數目int counts=1;//信息總條數int pageCounts=1;//總頁數

try{PreparedStatement ps=conn.prepareStatement(queryCount);ResultSet rs=ps.executeQuery();if(rs.next()){counts=Integer.parseInt(rs.getString(1));}



%><body bgcolor="#FFFFFF">          <br>  <p align="left">   <a href=>
//計算總頁數if(counts%pageSizes==0){pageCounts=counts/pageSizes;}else{pageCounts=counts/pageSizes+1;}

if(intPage>pageCounts){intPage=pageCounts;}int i=(intPage-1)*pageSizes;

ps=conn.prepareStatement(query);ResultSet rs1=ps.executeQuery();/*while(rs1.next()){String temp=rs1.getString("title");out.println(temp);}*/if(counts!=1){for( int  j=0; j<i ; j++)rs1.next();}//out.println(rs1+"<BR><BR><BR> ");

 

  i=0;while(rs1.next()&&i<pageSizes){ if(counts==0) {out.println("<font size=4 color=red>沒有您想看的數據!</font>");}%>

          <tr>            <td width="12%" height="7">              <p align="center">                <%= rs1.getString("article_id")%>              </p>            </td>            <td width="13%" height="7">              <div align="center">                <%= rs1.getString("types")%>              </div>            </td>            <td width="47%" height="7">              <%title= rs1.getString("title");              out.println(title);              %>            </td>            <td width="14%" align=&q

上一个:Oracle &amp; JSP 开发的小型信息管理系统 (四) 源代码3
下一个:Oracle &amp; JSP 开发的小型信息管理系统 (二) 源代码1

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,