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

推荐订阅源

U
Unit 42
Help Net Security
Help Net Security
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
T
Tor Project blog
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
Security Latest
Security Latest
Latest news
Latest news
Last Week in AI
Last Week in AI
博客园 - 司徒正美
P
Privacy International News Feed
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
腾讯CDC
博客园 - 聂微东
Scott Helme
Scott Helme
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
I
Intezer
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 热门话题
有赞技术团队
有赞技术团队
S
Secure Thoughts
WordPress大学
WordPress大学
The Cloudflare Blog
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Cyberwarzone
Cyberwarzone
S
Security Affairs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
L
LINUX DO - 最新话题
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Securelist
S
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 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>