SlideShare a Scribd company logo
1 of 9
04/06/2013 - 05/06/2013
BKBIET Phase I
Day 2 , Day 3
Thursday, 13 June 13
Today....
✤ Technical
✤ Servlet Platform
✤ tomcat
✤ Database
✤ postgreSQL,mysql,h2
✤ Atlassian - Jira
Thursday, 13 June 13
Servlets
✤ Servlets - Java CGI?
✤ run inside a servlet container
✤ encapsulate HTTP in java objects
✤ HTTPServletRequest
✤ HTTPServletResponse
✤ provide methods to process HTTP methods
✤ doGet
✤ doPost
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
Thursday, 13 June 13
Exercise!
✤ Create a Hello World Servlet!
✤ create a project in eclipse
✤ create src file
✤ create web.xml file
✤ add source/details
✤ deploy!
✤ Development Stations!!
Thursday, 13 June 13
Databases
✤ Relational Databases
✤ ACID
✤ Transactions
✤ JDBC
✤ Database Connections
✤ Queries
✤ ResultSets!
Thursday, 13 June 13
Exercise
✤ Create a db bkbiet
✤ Create a table bkbiet
✤ id
✤ name
✤ age
✤ email
✤ Use java to connect to db
✤ insert your own data in table
CREATE TABLE `bkbiet`.`bkbiet` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NOT NULL ,
`stream` VARCHAR(45) NOT NULL ,
`email` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `id_UNIQUE` (`id` ASC) );
String insertTableSQL = "INSERT INTO DBUSER"
! ! + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES"
! ! + "(?,?,?,?)";
PreparedStatement preparedStatement =
dbConnection.prepareStatement(insertTableSQL);
preparedStatement.setInt(1, 11);
preparedStatement.setString(2, "mkyong");
preparedStatement.setString(3, "system");
preparedStatement.setTimestamp(4, getCurrentTimeStamp());
// execute insert SQL stetement
preparedStatement .executeUpdate();
Thursday, 13 June 13
Templates
✤ Difficult to write long html pages
✤ requires templates
✤ Enter JSP
✤ Servlets feed data(model) to jsp
✤ converts to html pages
✤ JSP get converted to servlets at runtime
Thursday, 13 June 13
MVC Recall
✤ Model-View-Controller
✤ separate the data from the view
✤ Servlet: Controller
✤ DAO: Data Access Object
✤ View: JSP
Thursday, 13 June 13
Exercise
✤ Create a web site for users
✤ enter their details into the db
✤ create a page to view all details
✤ search for a user
<HTML>
<HEAD>
<TITLE>A Sample Form Using GET</TITLE>
</HEAD>
<BODY>
<FORM ACTION="http://localhost:8080/bkbiet/
BKBIETServlet" METHOD=”POST”>
<CENTER>
Name:
<INPUT TYPE="TEXT" NAME="name"
VALUE="Joe"><BR>
Last name:
<INPUT TYPE="TEXT" NAME="age" VALUE="26"><BR>
<INPUT TYPE="email" NAME="email"
VALUE="abc@example.com"><P>
<INPUT TYPE="SUBMIT">
<!-- Press this button to submit form -->
</CENTER>
</FORM>
</BODY>
</HTML>
Thursday, 13 June 13

More Related Content

What's hot

利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计Dehua Yang
 
ReactJS & Material-ui Hello world
ReactJS & Material-ui Hello worldReactJS & Material-ui Hello world
ReactJS & Material-ui Hello worldDaniel Lim
 
Getting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG DenmarkGetting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG DenmarkMauricio (Salaboy) Salatino
 
Real World Mocking In Swift
Real World Mocking In SwiftReal World Mocking In Swift
Real World Mocking In SwiftVeronica Lillie
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019Matt Raible
 
5 kinesis lightning
5 kinesis lightning5 kinesis lightning
5 kinesis lightningBigDataCamp
 
Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Fastly
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core DataInferis
 
Multi-threaded CoreData Done Right
Multi-threaded CoreData Done RightMulti-threaded CoreData Done Right
Multi-threaded CoreData Done Rightmorrowa_de
 
Distributed in memory data grid
Distributed in memory data gridDistributed in memory data grid
Distributed in memory data gridAlexander Albul
 
Potential gotchas in making a backbone app
Potential gotchas in making a backbone appPotential gotchas in making a backbone app
Potential gotchas in making a backbone appVignesh Nandha Kumar
 
Quick MySQL performance check
Quick MySQL performance checkQuick MySQL performance check
Quick MySQL performance checkTom Diederich
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module DevelopmentJay Harris
 
Pragmatic Introduction to React — Maayan Glikser
Pragmatic Introduction to React — Maayan GlikserPragmatic Introduction to React — Maayan Glikser
Pragmatic Introduction to React — Maayan Glikser500Tech
 
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkReactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkRed Hat Developers
 

What's hot (18)

利用Init connect做mysql clients stat 用户审计
 利用Init connect做mysql clients stat 用户审计 利用Init connect做mysql clients stat 用户审计
利用Init connect做mysql clients stat 用户审计
 
ReactJS & Material-ui Hello world
ReactJS & Material-ui Hello worldReactJS & Material-ui Hello world
ReactJS & Material-ui Hello world
 
Getting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG DenmarkGetting Started With #Drools 6 Slides - JBUG Denmark
Getting Started With #Drools 6 Slides - JBUG Denmark
 
Real World Mocking In Swift
Real World Mocking In SwiftReal World Mocking In Swift
Real World Mocking In Swift
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Morocco 2019
 
5 kinesis lightning
5 kinesis lightning5 kinesis lightning
5 kinesis lightning
 
Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015
 
Adventures in Multithreaded Core Data
Adventures in Multithreaded Core DataAdventures in Multithreaded Core Data
Adventures in Multithreaded Core Data
 
Cookies
CookiesCookies
Cookies
 
Week6
Week6Week6
Week6
 
Fluent plugin-dstat
Fluent plugin-dstatFluent plugin-dstat
Fluent plugin-dstat
 
Multi-threaded CoreData Done Right
Multi-threaded CoreData Done RightMulti-threaded CoreData Done Right
Multi-threaded CoreData Done Right
 
Distributed in memory data grid
Distributed in memory data gridDistributed in memory data grid
Distributed in memory data grid
 
Potential gotchas in making a backbone app
Potential gotchas in making a backbone appPotential gotchas in making a backbone app
Potential gotchas in making a backbone app
 
Quick MySQL performance check
Quick MySQL performance checkQuick MySQL performance check
Quick MySQL performance check
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
Pragmatic Introduction to React — Maayan Glikser
Pragmatic Introduction to React — Maayan GlikserPragmatic Introduction to React — Maayan Glikser
Pragmatic Introduction to React — Maayan Glikser
 
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech TalkReactive Quarkus – A Java Mutiny! | DevNation Tech Talk
Reactive Quarkus – A Java Mutiny! | DevNation Tech Talk
 

Similar to Bkbiet day2 & 3

Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWTtom.peck
 
Get Back in Control of Your SQL with jOOQ at #Java2Days
Get Back in Control of Your SQL with jOOQ at #Java2DaysGet Back in Control of Your SQL with jOOQ at #Java2Days
Get Back in Control of Your SQL with jOOQ at #Java2DaysLukas Eder
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLLukas Eder
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component PresentationJohn Coonen
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Zianed Hou
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long jaxconf
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
05 status-codes
05 status-codes05 status-codes
05 status-codessnopteck
 
02 up close with servlets
02 up close with servlets02 up close with servlets
02 up close with servletsdhrubo kayal
 

Similar to Bkbiet day2 & 3 (20)

servlets
servletsservlets
servlets
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWT
 
Advance java
Advance javaAdvance java
Advance java
 
Get Back in Control of your SQL
Get Back in Control of your SQLGet Back in Control of your SQL
Get Back in Control of your SQL
 
Get Back in Control of Your SQL with jOOQ at #Java2Days
Get Back in Control of Your SQL with jOOQ at #Java2DaysGet Back in Control of Your SQL with jOOQ at #Java2Days
Get Back in Control of Your SQL with jOOQ at #Java2Days
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Java and xml
Java and xmlJava and xml
Java and xml
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
 
Presentation
PresentationPresentation
Presentation
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
05 status-codes
05 status-codes05 status-codes
05 status-codes
 
Requery overview
Requery overviewRequery overview
Requery overview
 
02 up close with servlets
02 up close with servlets02 up close with servlets
02 up close with servlets
 

Recently uploaded

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 

Bkbiet day2 & 3

  • 1. 04/06/2013 - 05/06/2013 BKBIET Phase I Day 2 , Day 3 Thursday, 13 June 13
  • 2. Today.... ✤ Technical ✤ Servlet Platform ✤ tomcat ✤ Database ✤ postgreSQL,mysql,h2 ✤ Atlassian - Jira Thursday, 13 June 13
  • 3. Servlets ✤ Servlets - Java CGI? ✤ run inside a servlet container ✤ encapsulate HTTP in java objects ✤ HTTPServletRequest ✤ HTTPServletResponse ✤ provide methods to process HTTP methods ✤ doGet ✤ doPost public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Hello World!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); } } Thursday, 13 June 13
  • 4. Exercise! ✤ Create a Hello World Servlet! ✤ create a project in eclipse ✤ create src file ✤ create web.xml file ✤ add source/details ✤ deploy! ✤ Development Stations!! Thursday, 13 June 13
  • 5. Databases ✤ Relational Databases ✤ ACID ✤ Transactions ✤ JDBC ✤ Database Connections ✤ Queries ✤ ResultSets! Thursday, 13 June 13
  • 6. Exercise ✤ Create a db bkbiet ✤ Create a table bkbiet ✤ id ✤ name ✤ age ✤ email ✤ Use java to connect to db ✤ insert your own data in table CREATE TABLE `bkbiet`.`bkbiet` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(45) NOT NULL , `stream` VARCHAR(45) NOT NULL , `email` VARCHAR(45) NOT NULL , PRIMARY KEY (`id`) , UNIQUE INDEX `id_UNIQUE` (`id` ASC) ); String insertTableSQL = "INSERT INTO DBUSER" ! ! + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES" ! ! + "(?,?,?,?)"; PreparedStatement preparedStatement = dbConnection.prepareStatement(insertTableSQL); preparedStatement.setInt(1, 11); preparedStatement.setString(2, "mkyong"); preparedStatement.setString(3, "system"); preparedStatement.setTimestamp(4, getCurrentTimeStamp()); // execute insert SQL stetement preparedStatement .executeUpdate(); Thursday, 13 June 13
  • 7. Templates ✤ Difficult to write long html pages ✤ requires templates ✤ Enter JSP ✤ Servlets feed data(model) to jsp ✤ converts to html pages ✤ JSP get converted to servlets at runtime Thursday, 13 June 13
  • 8. MVC Recall ✤ Model-View-Controller ✤ separate the data from the view ✤ Servlet: Controller ✤ DAO: Data Access Object ✤ View: JSP Thursday, 13 June 13
  • 9. Exercise ✤ Create a web site for users ✤ enter their details into the db ✤ create a page to view all details ✤ search for a user <HTML> <HEAD> <TITLE>A Sample Form Using GET</TITLE> </HEAD> <BODY> <FORM ACTION="http://localhost:8080/bkbiet/ BKBIETServlet" METHOD=”POST”> <CENTER> Name: <INPUT TYPE="TEXT" NAME="name" VALUE="Joe"><BR> Last name: <INPUT TYPE="TEXT" NAME="age" VALUE="26"><BR> <INPUT TYPE="email" NAME="email" VALUE="abc@example.com"><P> <INPUT TYPE="SUBMIT"> <!-- Press this button to submit form --> </CENTER> </FORM> </BODY> </HTML> Thursday, 13 June 13