一、application
application的作用域:在服务器的打开和关闭之间有效
//应该先拿值
Integer count=(Integer)application.getAttribute("count");
if(count!=null){//拿到了 说明以前有人访问过
count++;//在原来的访问量上递增1
}
else{
count=1;
}
application.setAttribute("count", count);
二、JavaBean封装
封装在Java Resources的src中
如:
数据库辅助类代码:
//两个静态常量
private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
private static final String CNAME="oracle.jdbc.driver.OracleDriver";
/**
* 加载驱动
*/
static {
try {
Class.forName(CNAME);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建连接
* @return
*/
public static Connection getCon() {
Connection con=null;
try {
con=DriverManager.getConnection(URL, "scott", "tiger");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
/**
* 关闭资源
* @param con 连接
* @param ps 执行对象
* @param rs 结果集
*/
public static void myClose(Connection con,PreparedStatement ps,ResultSet rs) {
try {
if(con!=null&&!con.isClosed()) {
con.close();
}
if(ps!=null) {
ps.close();
}
if(rs!=null) {
rs.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
然后就可以在这里连接数据库和写方法。