• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
246
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 04/06/2013 - 05/06/2013BKBIET Phase IDay 2 , Day 3Thursday, 13 June 13
  • 2. Today....✤ Technical✤ Servlet Platform✤ tomcat✤ Database✤ postgreSQL,mysql,h2✤ Atlassian - JiraThursday, 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✤ doPostpublic 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 tableCREATE 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 stetementpreparedStatement .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 runtimeThursday, 13 June 13
  • 8. MVC Recall✤ Model-View-Controller✤ separate the data from the view✤ Servlet: Controller✤ DAO: Data Access Object✤ View: JSPThursday, 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