JSP ProgrammingTechnique By: Mr. PHUPHA PUNYAPOTASAKUL ( ภูผา ปัญญาโพธาสกุล )
2.
Searching Basic concept:Build SQL based on input criteria prod_name like ? and cat_id=? เติม AND หรือไม่เติม boolean is_first=true;
3.
Joining SELECT *from book b, category c WHERE b.cat_id=c.cat_id and c.cat_name like ? Many-2-Many อาจจะเกิด duplicate record SELECT distinct b.* from book b, bclink bc, category c where b.book_id=bc.book_id and bc.cat_id=c.cat_id
4.
Boolean Search Booleansearch e.g. ( ยา | medical ) & general ใช้ StringTokenizer(in,"()|&!",true); Ignore space convert | & ! to OR AND NOT convert other to criteria e.g. book_name like ? put final result in ()
5.
Boolean Search ValidationInvalid search input may cause exception การตรวจสอบความถูกต้องของวงเล็บ Start from 0, open count increment, close count decrement No -1 during checking End up 0 การตรวจสอบความถูกต้องอื่นๆ State checking
6.
Paging หาจำนวน record Select count(*) from .. หรือ rs.last(); rs.getRow(); การไปยังหน้าที่ต้องการ ให้ npp คือ จำนวน record per page ให้ page คือ หน้าที่ต้องการแสดง เริ่มต้นจาก 1..
Paging หาว่ามีทั้งหมดกี่หน้า ให้ numrow คือจำนวน record ทั้งหมด ( int )Math. ceil (( float )numrow/npp); การแสดง icon back, next ให้ numpage คือจำนวนหน้าทั้งหมด แสดง icon back หาก page>1 แสดง icon next หาก page<numpage
9.
Data Formatting Number เช่น price DecimalFormat df= new DecimalFormat("#,###.0000"); Date เช่น วันที่คืน วันที่ยืม SimpleDateFormat sf= new SimpleDateFormat("d/M/yyyy"); sf.format(date); ปกติ date format จะอิงกับ reginal ของ OS เช่น แสดงชื่อเดือนเป็นภาษาไทย แสดงปีเป็น พุทธศักราช
10.
Data Formatting การเปลี่ยน Locale ของการแสดงผล Date Locale loc= new Locale("en","US"); SimpleDateFormat sf= new SimpleDateFormat("d/M/yyyy",loc);
11.
Data Formatting String ปัญหาที่อาจเกิดขึ้น เช่น จำนวนนักเรียน < ปัจจุบัน แต่จำนวนหนังสือ > ปัจจุบัน <input value="She is "Hero".."> <a href="book.jsp?name=Tom&Jerry" "&","<",">","\"","\'" เปลี่ยนเป็น "&","<",">",""","'"
12.
Data inputting Number อาจมีการ input 1,000.25 ซึ่งจะผิด format และเกิด Exception ควรตัด comma ออก Date ใช้ function parse(input) ใน SimpleDateformat ร่วมกับ Calendar picker
Resource Controller สร้าง Class ชื่อว่า ResourceCtrl ทุกครั้งที่ get Connection, สร้าง Statement, execute Query ให้ทำผ่าน Class นี้ Class นี้จะบันทึก connection, statement, resultset เก็บไว้ การ close ให้ทำผ่าน Class นี้ด้วย Class นี้จะ mark เอาไว้ว่า object ไหนถูก close แล้ว สุดท้ายให้ class นี้ทำการ close object ทั้งหมดที่ยังไม่เคยถูก close ใน finally block
Personalization แต่ละ Session จะมีการแสดงผลที่แตกต่างกัน Time zone Language / Regional Date format / Number format การใช้ cookie หรือ Database เพื่อจำว่า user แต่ละคน ควรจะใช้ setting แบบใด
Sending Email http:// java . sun . com / products / javamail / Using SMTP Server Unless you're using Java SE 6, you will also need the JavaBeans Activation Framework http :// java . sun . com / products / javabeans / jaf / index . jsp Authentication