1
JSP
JSP (Java Server Pages): Script language
server perl, php asp cold
fusion JAVA JAVA
HTML
File JSP file JAVA
JSP
JSP ...
2
JSP)
JSP Engine
HTTP
Response) HTML
JSP
1. Write Once Run Anywhere
: Mac OS,
Linux Windows
2. Component Reusable :
Java ...
3
JSP
3. JAVA Extension :JSP
Object
Oriented Programming) , Thread
(Multithreading)
ErrorHandling)
4. Separation of Dynami...
4
1. Select query
2. Update query
3. Insert query
4. Delete query
Select query
Select ( )
Form ( )
Where ( )
Group by ( )
...
5
SELECT < >
FROM < >
WHERE < >
SELECT ---
,)
FROM ---
SELECT
WHERE---
FROM
SQL SELECT
6
Table
SQL
WHERE
Table) SQL WHERE
1
1
1. Operators = (
2. LIKE
7
1. WHERE
NOT
<> =
,-,*,/
2. Like
widecard
,??,%
3.
COUNT,SUM,AVG.MIN,MAX
Select Count(id) From
stdinfo
4.
1
stdinfo id)
...
8
subject), rid) , teacher)
SELECT
stdinfo.id,stdinfo.fname,stdinfo.lname,substd.subject
FROMstdinfo,substd WHERE stdinfo....
9
JSP
1. WebContent--> New --> JSP file
Search.jsp
2. Search.jsp
Web Page
,
10
SearchServlet.java
1. Package com.controller--> New -->
Servlet SearchServlet
2. SearchServlet.java Method
doPost
11
MemberDAO.java
3. MemberDAO.java
Table
12
Operators =
(
13
14
LIKE
15
SearchServlet..java
4. SearchServlet..java Class
MemberDAO
Combo box
Search.jsp
5.
Search.jsp
16
Code Class Search
<body>
<form action="SearchServlet" method="post">
<center>
<table>
<tr>
<td>
<select name="trpe">
<o...
17
<option
value="all"> </option>
<option
value="name"> </option>
<option
value="namelike"> </option></select>
</td>
<td><...
18
<td
align="center">Password</td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td alig...
19
<td><a href="#"> </a></td>
</tr>
<% }%>
</table>
</center>
<% }%>
</form>
</body>
Code Class MembersDAO
//Method
public...
20
try{
dbc.createConnection();
stmt = dbc.getStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
mem =newMembersB...
21
mem.setMember_address(rs.getString("member_add
ress"));
mem.setMember_county(rs.getString("member_coun
ty"));
mem.setMe...
22
//Method
publicArrayList<MembersBean>getAllMembersByName(S
tring name){ ArrayList<MembersBean>memlist =
newArrayList<Me...
23
mem.setMember_firstname(rs.getString("member_fir
stname"));
mem.setMember_lastname(rs.getString("member_las
tname"));
m...
24
memlist.add(mem);
}
}catch(SQLException e){
e.printStackTrace();
}
returnmemlist;
}
//Method
publicArrayList<MembersBea...
25
mem.setMember_username(rs.getString("member_u
sername"));
mem.setMember_password(rs.getString("member_p
assword"));
mem...
26
mem.setMember_number(rs.getString("member_num
ber"));
mem.setMember_image(rs.getString("member_imag
e"));
memlist.add(m...
27
String page = "Search.jsp";
System.out.println("trpe : "+trpe);
System.out.println("keyword : "+keyword);
MemberDAO md ...
28
1. Table
2. Operators = (
3. Like
29
 http://www.choosak.com/page-29/
 http://suchada51122470136.blogspot.com/
 http://www.sut.ac.th/ist/Courses/204204/L...
Upcoming SlideShare
Loading in …5
×

Jsp

2,017 views
1,964 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,017
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Jsp

  1. 1. 1 JSP JSP (Java Server Pages): Script language server perl, php asp cold fusion JAVA JAVA HTML File JSP file JAVA JSP JSP tag) HTML JSP HTM HTML Server Side) HTML JSP HTTP Request) JSP HTTP JSP JSP Engine (JSP Engine
  2. 2. 2 JSP) JSP Engine HTTP Response) HTML JSP 1. Write Once Run Anywhere : Mac OS, Linux Windows 2. Component Reusable : Java Bean)
  3. 3. 3 JSP 3. JAVA Extension :JSP Object Oriented Programming) , Thread (Multithreading) ErrorHandling) 4. Separation of Dynamic and Static Content HTML SQL SQL) MySQL, MsSQL, PostgreSQL MS Access MySQL Open Source Linux Windows SQL 4
  4. 4. 4 1. Select query 2. Update query 3. Insert query 4. Delete query Select query Select ( ) Form ( ) Where ( ) Group by ( ) Query Statement) SELECT SELECT
  5. 5. 5 SELECT < > FROM < > WHERE < > SELECT --- ,) FROM --- SELECT WHERE--- FROM SQL SELECT
  6. 6. 6 Table SQL WHERE Table) SQL WHERE 1 1 1. Operators = ( 2. LIKE
  7. 7. 7 1. WHERE NOT <> = ,-,*,/ 2. Like widecard ,??,% 3. COUNT,SUM,AVG.MIN,MAX Select Count(id) From stdinfo 4. 1 stdinfo id) , fname), lname) 2 substd
  8. 8. 8 subject), rid) , teacher) SELECT stdinfo.id,stdinfo.fname,stdinfo.lname,substd.subject FROMstdinfo,substd WHERE stdinfo.id=substd.rid
  9. 9. 9 JSP 1. WebContent--> New --> JSP file Search.jsp 2. Search.jsp Web Page ,
  10. 10. 10 SearchServlet.java 1. Package com.controller--> New --> Servlet SearchServlet 2. SearchServlet.java Method doPost
  11. 11. 11 MemberDAO.java 3. MemberDAO.java Table
  12. 12. 12 Operators = (
  13. 13. 13
  14. 14. 14 LIKE
  15. 15. 15 SearchServlet..java 4. SearchServlet..java Class MemberDAO Combo box Search.jsp 5. Search.jsp
  16. 16. 16 Code Class Search <body> <form action="SearchServlet" method="post"> <center> <table> <tr> <td> <select name="trpe"> <option value="00" selected="selected"> </option>
  17. 17. 17 <option value="all"> </option> <option value="name"> </option> <option value="namelike"> </option></select> </td> <td><input type="text" id="keyword" name="keyword"></td> <td><input type="submit" value=" "></td> </tr> </table> </center> <%ArrayList<MembersBean>memberlist = (ArrayList<MembersBean>)request.getAttribute("member" ); if(memberlist != null){%> <center> <table border="2"> <tr> <td align="center"> </td> <td align="center">User</td>
  18. 18. 18 <td align="center">Password</td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <%for(int i=0;i<memberlist.size();i++){ MembersBeanmem = (MembersBean)memberlist.get(i);%> <tr> <td><%=mem.getMember_id() %></td> <td><%=mem.getMember_username() %></td> <td><%=mem.getMember_password() %></td> <td><%=mem.getMember_firstname() %></td> <td><%=mem.getMember_lastname() %></td> <td><a href="#"> </a></td>
  19. 19. 19 <td><a href="#"> </a></td> </tr> <% }%> </table> </center> <% }%> </form> </body> Code Class MembersDAO //Method publicArrayList<MembersBean>getAllMembers(){ ArrayList<MembersBean>memlist = newArrayList<MembersBean>(); MembersBeanmem = newMembersBean(); String sql ="SELECT * FROM membersbook";
  20. 20. 20 try{ dbc.createConnection(); stmt = dbc.getStatement(); rs = stmt.executeQuery(sql); while(rs.next()){ mem =newMembersBean(); mem.setMember_id(rs.getInt("member_id")); mem.setMember_username(rs.getString("memb er_username")); mem.setMember_password(rs.getString("member_p assword")); mem.setMember_firstname(rs.getString("member_fir stname")); mem.setMember_lastname(rs.getString("member_las tname")); mem.setMember_sex(rs.getString("member_sex"));
  21. 21. 21 mem.setMember_address(rs.getString("member_add ress")); mem.setMember_county(rs.getString("member_coun ty")); mem.setMember_email(rs.getString("member_email" )); mem.setMember_number(rs.getString("member_num ber")); mem.setMember_image(rs.getString("member_imag e")); memlist.add(mem); } }catch(SQLException e){ e.printStackTrace(); } returnmemlist; }
  22. 22. 22 //Method publicArrayList<MembersBean>getAllMembersByName(S tring name){ ArrayList<MembersBean>memlist = newArrayList<MembersBean>(); MembersBeanmem = newMembersBean(); String sql ="SELECT * FROM membersbook WHERE member_firstname ='"+name+"' "; try{ dbc.createConnection(); stmt = dbc.getStatement(); rs = stmt.executeQuery(sql); while(rs.next()){ mem =newMembersBean(); mem.setMember_id(rs.getInt("member_id")); mem.setMember_username(rs.getString("member_u sername")); mem.setMember_password(rs.getString("member_p assword"));
  23. 23. 23 mem.setMember_firstname(rs.getString("member_fir stname")); mem.setMember_lastname(rs.getString("member_las tname")); mem.setMember_sex(rs.getString("member_sex")); mem.setMember_address(rs.getString("member_add ress")); mem.setMember_county(rs.getString("member_coun ty")); mem.setMember_email(rs.getString("member_email" )); mem.setMember_number(rs.getString("member_num ber")); mem.setMember_image(rs.getString("member_imag e"));
  24. 24. 24 memlist.add(mem); } }catch(SQLException e){ e.printStackTrace(); } returnmemlist; } //Method publicArrayList<MembersBean>getAllMembersByNameLi ke(String name){ ArrayList<MembersBean>memlist = newArrayList<MembersBean>(); MembersBeanmem = newMembersBean(); String sql ="SELECT * FROM membersbook WHERE member_firstname LIKE'%"+name+"%' "; try{ dbc.createConnection(); stmt = dbc.getStatement(); rs = stmt.executeQuery(sql); while(rs.next()){ mem =newMembersBean(); mem.setMember_id(rs.getInt("member_id"));
  25. 25. 25 mem.setMember_username(rs.getString("member_u sername")); mem.setMember_password(rs.getString("member_p assword")); mem.setMember_firstname(rs.getString("member_fir stname")); mem.setMember_lastname(rs.getString("member_las tname")); mem.setMember_sex(rs.getString("member_sex")); mem.setMember_address(rs.getString("member_add ress")); mem.setMember_county(rs.getString("member_coun ty")); mem.setMember_email(rs.getString("member_email" ));
  26. 26. 26 mem.setMember_number(rs.getString("member_num ber")); mem.setMember_image(rs.getString("member_imag e")); memlist.add(mem); } }catch(SQLException e){ e.printStackTrace(); } returnmemlist; } Code Class SearchServlet protectedvoiddoPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { request.setCharacterEncoding("UTF-8"); String trpe = request.getParameter("trpe"); String keyword = request.getParameter("keyword");
  27. 27. 27 String page = "Search.jsp"; System.out.println("trpe : "+trpe); System.out.println("keyword : "+keyword); MemberDAO md = newMemberDAO(); if(trpe.equals("all")){ request.setAttribute("member", md.getAllMembers()); }elseif(trpe.equals("name")){ request.setAttribute("member", md.getAllMembersByName(keyword)); }else { request.setAttribute("member", md.getAllMembersByNameLike(keyword)); } }
  28. 28. 28 1. Table 2. Operators = ( 3. Like
  29. 29. 29  http://www.choosak.com/page-29/  http://suchada51122470136.blogspot.com/  http://www.sut.ac.th/ist/Courses/204204/Lecture/20420 4_47_09.pdf  http://www.cmm com/board/index.php?topic=  http://www.thaicreate.com/asp/asp-sql-command.html

×