DAO設計模式
產生的原因
JDBC不能出現在JSP頁面中
什么是DAO
J2EE組件層次
客戶端——》表示層--》業務層--》數據層(DAO)







異常 的處理通常由調用它的方法來處理
產生的原因
JDBC不能出現在JSP頁面中
什么是DAO
J2EE組件層次
客戶端——》表示層--》業務層--》數據層(DAO)
jsp+javabean開發(jsp接收參數,調用 javaBean)
開發速度快,有一個問題,藕合性高,維護困難
一個人開發使用,人多了不好控制
jsp+DAO設計模式
jsp+servlet+javabean(servlet調用javabean)
jsp:UI
javaBean:重復調用
servlet:安全性高性能也高,
jsp兩種跳轉方式
jsp中有四種屬性范圍:page ,response,application,session
筆記下載
代碼下載地址:
/Files/guohua/TaglibProject.rar
hello.java
<%@ page contentType="text/html;charset=gb2312"%>
<%@page import ="java.sql.*"%>
<%--
使用JDBC連接Oracle數據庫
使用MLDN數據庫
用戶名:scott
密碼:tiger
--%>
<%!
String DBDRIVER="oracle.jdbc.driver.OracleDriver";
String DBURL="jadb:oracle:thin:@localhost:1521:mldn";
String DBUSER="scott";
String DBPASSWORD="tiger";
Connection conn=null;
statement stmt=null;
%>
<%try{Class.forname(DBDRIVER);
conn=DriverManger.getConnection(DBURL,DBUSER,DBPASSWORD);
//create table
String sql="CREATE TABLE mldnab(name vachar(20))";
stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}catch(Exception e){
out.println(e);
}
/**
*測試類構造器的調用順序
*/
public class ConstructorTest{
public static void main(String[] args){
C c=new C("hello");
}
}
class A{
public A(){
System.out.println("this is A");
}
}
class C extends B{
public C(String str){
super(str);
System.out.println("this is C");
}
}
public class ToStringTest{
public static void main(String[] args){
System.out.println(new Student("youName","20031001"));
}
}
/**
*通過這個程序,展示字符串求取子串的方法
*/
public class SubStringTest{
public static void main(String[] args){
String str="I am a Programmer";//定義字符串
for(int i=0;i<str.length();i++){
System.out.println("這是第"+i+"個子串:"+str.subString(i));
}}}
/**
*讀取鍵盤輸入
*/
import javax.swing.JOptionPane;
public class InputTest{
public static void main(String[] args){
String strName=JOptionPane.showInputDialog("Input your name:");
String strAge=JOptionPane.showInputDialog("Input your age:");
int age=Integer.parseInt(strAge);
System.out.println("Welcome you :"+strName);
System.out.println("你還有"+(60-age)+"年可以退休了??!");
System.exit(0);
}
}
/**
*通過這個程序,測試格式器的使用方法
*/
import java.text.NumberFormat;
import java.util.locale;
public class FormateValue{
public static void main(String[] args){
double x=100000.0/3;
System.out.println("the value is :"+x);
//首先以默認地區的格式器來輸出
System.out.println("接下來輸出的是美國地區的格式器的結果:");
NumberFormat number=NumberFormat.getNumberInstance(Locale.US);
NumberFormat number=NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat percent=NumberFormat.getPercentInstance(Locale.US);
FormatValue fm=new FormatValue();
fm.print(number,x);
fm.print(currency.x);
fm.print(percent,x);
System.out.println("接下來輸出的是默認地區的格式器的結果:");
NubmerFormat nu=NumberFormat.getNumberInstance();
NubmerFormat cu=NumberFormat.getCurrencyInstance();
NubmerFormat be=NumberFormat.getPercentIntstance();
fm.print(nu,x);
fm.print(cu,x);
fm.print(pe,x);
}
public void print(NubmerFormat nu,double x){
System.out.println(nu.format(x));
}
}
/**
*查找特定的子串
*/
public class FindSubstring{
public static void main(String[] args){
String str="Welcome the body.";
System.out.println("Find the substring boy occurrence:"+str.indexOf("boy"));//查找子串
System.out.println("Find the substring by occurrence: "+str.indexOf("by"));//查找子串
System.out.println("Find the char t occurrence: "+str.indexOf('t'));//查找特定的字符
System.out.println("Test the string begin with wel.:"+str.startsWith("wel"));//是否以"wel"開始
System.out.pritnln("Test the string end with body.:"+str.endWith("boy"));//是否以"boy"結束
}
}