·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » Oracle & JSP 开发的小型信息管理系统 (三) 源代码2

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

类别: JAVA教程  评论数:0 总得分:0

//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="css/style.css"></head>

<%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;//每??锢示信息?的块nt counts=1;//信息???l?甸nt pageCounts=1;//?????导BR>
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="add.jsp">添加信息</a>           <a href="index.jsp">返回首??</a>        </p>         <p>&nbsp;</p>  <table width="700" border="1" cellspacing="0" cellpadding="0" align="center" bordercolorlight="#000000" bordercolordark="#FFFFFF">    <tr bgcolor="#99CCFF">      <td height="10" bgcolor="#B5D85E">        <div align="center">          <b>管 理 界 面</b>        </div>      </td>    </tr>    <tr>      <td height="49">        <%-- 分?? --%>          <table border="1" cellspacing="0" width="90%" bgcolor="#F0F8FF" bordercolorlight="#000000" bordercolordark="#FFFFFF" align="center">          <tr>            <td width="12%" align="center">              <strong>ID ??</strong>            </td>            <td width="13%" align="center">              <b>?? 型</b>            </td>            <td width="47%" align="center">              <strong>信 息 名 费</strong>            </td>            <td width="14%" align="center">              <strong>修 改</strong>            </td>            <td width="14%" align="center">              <strong>?h 除</strong>            </td>          </tr>          <%

//??算?????甸f(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="center" height="7">              <a href="edit.jsp?id=<%=rs1.getInt("article_id")%>">修 改</a>            </td>            <td width="14%" align="center" height="7">              <a href="delete.jsp?id=<%=rs1.getInt("article_id")%>&title=<%=title%>">?h 除</a>            </td>          </tr>          <% i++;}%>        </table>        <%

}catch(SQLException se1){se1.printStackTrace();}finally{}

conn.close(); %>      </td>    </tr>

  </table>    <form action="manage.jsp" method="post" >第<%=intPage%>??,共<%=pageCounts%>??

<%if(intPage<pageCounts){%><a href="manage.jsp?strPage=<%=intPage+1%>">下一??</a><%}if(intPage>1){%>  <a href="manage.jsp?strPage=<%=intPage-1%>">上一??</a><%}%><br>到第<input type="text" maxlength="5" name="strPage" value="1"/>??咄行查看<input type="submit" value="催帐" class="buttonface"/>

</form>

         <br>  <p align="left">   <a href="add.jsp">添加信息</a>           <a href="index.jsp">返回首??</a>        </p>  <P>&nbsp;</P></body>

</html>

//******************************************FilterSpecial .java过滤用户输入

package moonsoft.test.j2ee.news;



public class FilterSpecial {  public FilterSpecial()    {  }  public static String filter(String input)  {    if(!hasSpecialChars(input))    {     return input;    }    StringBuffer filtered =new StringBuffer(input.length());    char c;    for(int i=0; i<=input.length()-1; i++)    {    c=input.charAt(i);    switch(c)    {      case \'<\':filtered.append("&lt;"); break;      case \'>\':filtered.append("&gt;"); break;      case \'"\':filtered.append("&uot;"); break;      case \'&\':filtered.append("&amp;"); break;      default: filtered.append(c);    }          }    return (filtered.toString());  }  public static boolean hasSpecialChars(String input)  {    boolean flag=false;    if((input!=null)&&(input.length()>0))    {      char c;      for(int i=0; i<=input.length()-1; i++)      {        c=input.charAt(i);              switch(c)        {          case \'>\': flag=true; break;          case \'<\': flag=true; break;          case \'"\': flag=true; break;          case \'&\': flag=true; break;

        }      }    }    return flag;  }}



-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1