惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

博客园 - feeling

头疼! 回家了! 买房日记 好久没写blog了。最近感觉自己老了 关于应用项目的实际价值在哪里 现在的技术已经不重要了? 使用存储过程(带参数的) 我的第一个jsp程序 读取数据库中的一个表 - feeling - 博客园 静思人生 济南行 坚持、冷静、忍耐 休假结束了! .net流程开发平台的一些难点(1) 想开发一套流程开发的平台 。基于.net的 归家了!庆祝一下了!房价涨了!郁闷一下了 vs.net调试变慢的问题 对于vs.net用一段时间后发现调试变慢的问题 MSN 病毒 我的一下午 什么也做不进去 为什么
我的第二个jsp程序 使用javabean
feeling · 2005-06-22 · via 博客园 - feeling

   就是把第一个jsp程序中的后台部分封装到了javabean中了,在我看来javabean就和asp中ocx控件一样。很简洁也很好用,他是符合jsp使用的java类,本质上和java没什么区别。
一下是bean的代码:
/*
 * 创建日期 2005-6-21
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */

package test;

import java.sql.*;

/**
 * @author Administrator
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */

public class HelloWorld {
 public ResultSet rs =null;
 public Connection con=null;
 public  HelloWorld()
 {
   
 }
 public String GetName()
 {
     return "用javabean生成rs 在页面中调用后的结果列表:";
 }
 public ResultSet GetList() throws SQLException
 {
  try{
     String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=liveflow";
 
 
           String user ="sa";//数据库用户名
           String password = "sa";//数据库用户密码
           String sqlStr = "select top 100 * from employee_base";
           Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
           
     con = DriverManager.getConnection( url, user, password );
     

           Statement st =  con.createStatement();
             

           rs = st.executeQuery( sqlStr );
          
    }
  catch(Exception ee)
  {
              System.out.println("connect db error:"+ee.getMessage());
        }
        //finally
        //{
  // con.close();
        //}
 return rs;
 }

}
以下是jsp的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
import="java.sql.*"
contentType="text/html; charset=GBK"
pageEncoding="GBK"
%>
<META http-equiv="Content-Type" content="text/html; charset=GBK">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>BeanTest.jsp</TITLE>
</HEAD>
<BODY>
<jsp:useBean class="test.HelloWorld" id="hello"></jsp:useBean>
<%= hello.GetName()%>
<%
   int currpage=0;
   try
   {
   currpage=java.lang.Integer.parseInt(request.getParameter("page")) ;//当前页码}
   }
   catch(Exception ex)
   {
      ex.getMessage();
   }
  
   //int rownum=0;//记录行数
   //int pagesize=5;
   //int totalPages=0;

   ResultSet rs=hello.GetList();//得到记录集
   //rownum=rs.getInt("total_rows");//得到总行数
   //totalPages = rownum / pagesize + 1;//总页数
       // if((rownum % pagesize == 0)&&(rownum != 0)){
           // totalPages = totalPages -1;}
  

%>
<table border=1>

<%
//if(java.lang.Integer.parseInt(request.getParameter("page"))>=1)
//{
  //  rs.absolute(currpage*pagesize+1);
//}%>
<%while(rs.next())
            {%>
       <tr><td><%=rs.getString("employee_id")%></td><td><%=rs.getString("employee_name")%></td><td><%=rs.getString("post_name")%></td><td><%=rs.getString("rela_phone")%></td><td><%=rs.getString(6)%></td></tr>
              
           <% }%>
           <tr><td><a href=BeanTest.jsp?page=<%=currpage-1%>>上一页</a>
          
          <a href=BeanTest.jsp?page=<%=currpage+1%>>下一页</a></td><tr>
           </table>
</BODY>
</HTML>