SlideShare a Scribd company logo
1 of 49
Download to read offline
Java	
  EE	
  Servlet	
  Tutorial

                                                          First Cookbook- Getting started with Model 2: Servlet and JSP




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Open%Source,%Reliable%and%Lightweight%
                             Java%EE%Applica;on%Server%




                      RESIN PRO   Web Profile   Health System   Cloud Support




Thursday, May 3, 12
Cookbook:	
  Intro	
  to	
  Serlvets	
  and	
  JSP
                 • This cookbook in the Java EE Servlet tutorial covers
                          building a simple listing in JSP and Servlets.

                 • This tutorial is part of Java EE Tutorial covering
                          JSP_2.2, and Servlets 3.0.

                 • The WIKI and step by step detailed instructions live
                          here:

                 • http://wiki4.caucho.com/
                          Building_a_simple_listing_in_JSP




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
About	
  tutorial
                 • Very	
  liEle	
  knowledge	
  of	
  HTML,	
  Java	
  and	
  JSP	
  is	
  assumed
                 • HTML	
  and	
  Java	
  not	
  covered	
  length,	
  but	
  pointers	
  in	
  the	
  right	
  
                          direc8on	
  

                 • Focus	
  is	
  Java	
  Servlets	
  and	
  JSP	
  (Java	
  Server	
  Pages)
                 • Use	
  whatever	
  IDE	
  you	
  would	
  like,	
  but	
  direc8ons	
  focus	
  on	
  
                          Eclipse




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
App	
  you	
  are	
  building
                                                                                                                                       Sorting




                                                                                                                                                 Remove




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Sidebar:	
  Why	
  Eclipse?
                 • Best?	
  No	
  not	
  really,	
  best	
  is	
  IntelliJ
                 • Eclipse	
  is	
  free	
  and	
  supports	
  Java	
  EE	
  well
                 • NetBeans	
  and	
  JDeveloper	
  are	
  from	
  Oracle,	
  they	
  are	
  good	
  too




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Running	
  tutorial	
  app	
  in	
  Eclipse




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Windows?	
  Try	
  Linux...	
  
                 • Java	
  is	
  write	
  once	
  run	
  anywhere,	
  so	
  you	
  can	
  develop	
  Java	
  anywhere
                 • Most	
  companies	
  deploy	
  Java	
  on	
  some	
  flavor	
  of	
  Linux
                 • You	
  can	
  use	
  Windows	
  for	
  development,	
  but...
                 • Probably	
  a	
  good	
  idea	
  to	
  get	
  familiar	
  with	
  produc8on	
  deployment	
  environment	
  anyway
                 • If	
  you	
  are	
  a	
  Windows	
  or	
  OSX	
  users,	
  I	
  suggest	
  installing	
  Ubuntu	
  (hEp://
                          www.ubuntu.com/)	
  or	
  CentOS	
  on	
  VMWare	
  or	
  Virtual	
  Box	
  and	
  making	
  that	
  your	
  main	
  
                          development	
  environment

                 • You	
  can	
  make	
  this	
  tutorial	
  work	
  for	
  you	
  on	
  OSX	
  and	
  Windows,	
  but	
  might	
  be	
  beEer	
  just	
  
                          to	
  go	
  with	
  a	
  fric8onless	
  approach.	
  This	
  way	
  you	
  can	
  focus	
  on	
  the	
  concepts	
  instead	
  of	
  
                          the	
  configura8on	
  woes

                 • Cloud	
  deployment	
  for	
  the	
  most	
  part	
  ==	
  Linux




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Outline
       •        1 Optional: Getting started Eclipse Java EE IDE
       •        2 Resources
       •        3 What is going to be in the project
       •        4 Creating model and Repository objects for books
                 • 4.1 Book model class
                 • 4.2 Are you new to Java?
                 • 4.3 BookRepository interface
       •        5 Servlets / JSP
                 • 5.1 Servlet Background
                 • 5.2 Creating your first Servlet
                      • 5.2.1 BookListServlet listing
                      • 5.2.2 Java EE / Servlets scopes (page, request, conversation, session, application)
       •        6 Creating your first JSP
                 • 6.1 Templates/JSTL versus Java scriptlets
                      • 6.1.1 /WEB-INF/pages/book-list.jsp listing
                      • 6.1.2 HTML background
                      • 6.1.3 JSTL c:forEach
       •        7 Setting up CDI
                 • 7.1 CDI META-INF/beans.xml
       •        8 Deploying with Eclipse
       •        9 Deploying from the command line
       •        10 Cookbooks and Tutorials




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Using	
  Eclipse	
  to	
  setup	
  Web	
  Project
                 • First go here to get Eclipse for Java EE: Install Guide for Eclipse for Java EE Indigo or higher.

                 • Screenshots to follows, but here is the basic steps to installing Eclipse and Java EE development
                          environment in one go

                 • Using Eclipse Indigo or higher
                 Install Resin (lightweight, fast, easy to use Java EE 6 Web Profile server) plugin:
                    1. Go to File menu -> New Project -> Dynamic Web Project
                    2. In New Dynamic Web Project Dialog-> New Runtime...
                    3. In New Runtime Dialog -> Download Additional Server Adapters -> Select Resin (Java EE Web Profile)
                       4.0.x
                    4. (Click Next and Ok until it installs Resin runtime)
                    5. (Eclipse needs to restart)

                 Setup new Web Project in Eclipse
                    1.       File -> New Project -> Dynamic Web Project
                    2.       In New Dynamic Web Project Dialog-> New Runtime...->Select Resin->Check create local server checkbox
                    3.       Step 2 of New Runtime...->Click Download and Install (you only have to do this once)
                    4.       Fill out project name etc. (bookstore).
                    5.       (Click Next and Ok until you are done)




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Install	
  Java	
  EE	
  6	
  Web	
  Profile
                • Go	
  to	
  File	
  menu	
  -­‐>	
  New	
  Project	
  -­‐>	
  Dynamic	
  Web	
  Project
                • In	
  New	
  Dynamic	
  Web	
  Project	
  Dialog-­‐>	
  New	
  Run8me...




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Crea8ng	
  a	
  new	
  web	
  project
                • Click	
  OK	
  and	
  Finish	
  and	
  Restart	
  to	
  restart	
  Eclipse

                • Crea8ng	
  a	
  new	
  Web	
  Project




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Crea8ng	
  a	
  simple	
  Book	
  lis8ng	
  for	
  our	
  bookstore
                • Create	
  a	
  new	
  Java	
  class	
  as	
  
                          follows:

                • Eclipse:	
  Right	
  Click	
  "Java	
  
                          Resources"	
  in	
  Project	
  Explorer	
  -­‐>	
  
                          New	
  -­‐>	
  Class	
  -­‐>	
  Package	
  
                          com.bookstore	
  -­‐>	
  Class	
  Name	
  -­‐>	
  
                          Book	
  (That	
  is	
  the	
  last	
  8me	
  I	
  will	
  
                          tell	
  you	
  how	
  to	
  create	
  a	
  class	
  in	
  
                          Eclipse.)

                • Add	
  8tle,	
  descrip8on,	
  price,	
  
                          pubDate	
  and	
  id	
  proper8es,	
  and	
  
                          the	
  toString	
  and	
  cloneMe	
  
                          methods	
  as	
  follows:




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Are	
  you	
  new	
  to	
  Java?
                 • If	
  you	
  are	
  new	
  to	
  Java	
  and	
  the	
  Book	
  class	
  seems	
  foreign	
  to	
  
                          you,	
  
                          • Read	
  up	
  on	
  Java	
  a	
  bit	
  Official	
  Java	
  tutorial.	
  
                          • Read	
  the	
  first	
  three	
  trails	
  (Ge>ng	
  Started,	
  Learning	
  the	
  Java	
  
                                    Language	
  and	
  EssenBal	
  Java	
  Classes),	
  
                          • Skip	
  ahead	
  to	
  Java	
  Beans.	
  Skimming	
  is	
  ok.	
  
                          • If	
  you	
  have	
  programmed	
  before,	
  most	
  things	
  you	
  will	
  pick	
  up	
  on	
  your	
  
                                    own.
                          • Then	
  come	
  back	
  here	
  :)
                 • Reminder:	
  The	
  methods	
  public	
  String	
  getId()	
  and	
  public	
  void	
  
                          setId(String	
  id)	
  would	
  define	
  a	
  property	
  called	
  id



   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Repository	
  Interface
                 • First	
  step	
  in	
  tutorial	
  not	
  going	
  to	
  actually	
  talk	
  to	
  a	
  database	
  
                          or	
  use	
  JDBC

                 • For	
  now,	
  just	
  using	
  collec8on	
  API
                 • Repository	
  object	
  encapsulates	
  how	
  an	
  object	
  gets	
  persisted,	
  
                          queried	
  and	
  updated	
  (CRUD	
  opera8ons)

                 • Let’s	
  define	
  an	
  interface	
  for	
  our	
  CRUD	
  opera8ons
                 • Later	
  we	
  use	
  JDBC/RDBMS	
  (MySQL),	
  JTA/RDBMS,	
  JCache,	
  
                          MongoDB,	
  etc.	
  instead	
  of	
  collec8on	
  API	
  




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepository	
  (DAO	
  like	
  object)
                • Eclipse:	
  Right	
  Click	
  "Java	
  Resources"	
  in	
  Project	
  Explorer	
  -­‐>	
  New	
  -­‐>	
  Interface	
  -­‐>	
  Package	
  
                          =	
  com.bookstore	
  -­‐>	
  Class	
  Name	
  =	
  Book	
  -­‐>	
  Click	
  Finish




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepositoryImpl	
  1	
  of	
  4
                • Actual	
  BookRepositoryImpl	
  just	
  uses	
  Java	
  collec8on	
  to	
  store	
  in	
  memory	
  (skim	
  don’t	
  
                          read)	
  Set’s	
  up	
  some	
  test	
  data




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepositoryImpl	
  2	
  of	
  4
                • Helper	
  methods	
  to	
  define	
  test	
  data,	
  add	
  method




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepositoryImpl	
  3	
  of	
  4
                • Interface	
  implementa8ons	
  using	
  collec8ons	
  API




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepositoryImpl	
  4	
  of	
  4
                • listBooks	
  and	
  removeBooks




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookRepositoryImpl	
  wrap	
  up
                 • This	
  BookRepositoryImpl	
  really	
  basic	
  class.	
  
                 • Largely	
  based	
  on	
  the	
  collec8ons	
  API
                 • You	
  can	
  find	
  out	
  more	
  informa8on	
  about	
  the	
  Java	
  collec8ons	
  
                          API	
  at	
  this	
  tutorial	
  trail.	
  

                 • A	
  full	
  discussion	
  of	
  collec8on	
  API	
  out	
  of	
  scope	
  for	
  cookbook
                 • JDBC	
  cookbook	
  coming	
  up	
  in	
  this	
  tutorial	
  series




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
@Applica8onScoped
                 • One	
  interesBng	
  thing	
  is	
  BookRepositoryImpl	
  uses	
  
                          @Applica2onScoped	
  annotaBon

                 • AnnotaBons	
  allow	
  you	
  to	
  add	
  meta-­‐data	
  to	
  Java	
  objects.	
  (To	
  
                          learn	
  more	
  see	
  this	
  annotaBons	
  tutorial)

                 • 	
  Applica2onScoped	
  specifies	
  a	
  bean	
  is	
  applicaBon	
  scoped
                 • Scoping	
  defines	
  a	
  lifecycle
                          • how	
  long	
  an	
  object	
  will	
  be	
  around
                 • ApplicaBonScoped	
  means	
  it	
  will	
  be	
  around	
  for	
  the	
  complete	
  
                          lifecycle	
  of	
  the	
  Web	
  ApplicaBon
                 •        This annotations has slightly different meanings depending on whether it is used with EJBs or Servlets. This annotation is part of the CDI support
                          added to Java EE 6 to handle Java Dependency Injection. To learn more about CDI go see this tutorial Java Dependency Injection and this one part 2
                          both written by the same author that is writing this tutorial now. :)




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
@Applica8onScoped




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Model	
  done,	
  now	
  controller
                 • Now	
  that	
  we	
  have	
  a	
  model	
  
                          • Book,	
  BookRepository
                 • Lets	
  define	
  our	
  web	
  controller	
  
                          • Servlet	
  controller	
  
                 • and	
  view	
  
                          • JSPs




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Servlet	
  Background
                 • A	
  servlet	
  is	
  a	
  Java	
  class	
  that	
  handles	
  HTTP	
  requests
                 • A	
  Java	
  web	
  applica8on	
  consists	
  of	
  one	
  or	
  more	
  servlet	
  
                          bundled	
  together	
  with	
  any	
  JSPs	
  and	
  Java	
  classes	
  it	
  needs	
  into	
  
                          a	
  war	
  file	
  (Web	
  Applica8on	
  Archive	
  file).

                 • Servlets	
  run	
  inside	
  of	
  a	
  container	
  (like	
  Caucho's	
  Resin)
                 • End	
  users	
  typically	
  use	
  a	
  Java	
  Web	
  Applica8on	
  through	
  a	
  web	
  
                          browser	
  like	
  Apple	
  Safari,	
  Google	
  Chrome,	
  Mozilla	
  FireFox	
  or	
  
                          Internet	
  Explorer




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Crea8ng	
  your	
  first	
  Servlet
                 • Eclipse:	
  Right	
  Click	
  "Java	
  Resources"	
  in	
  Project	
  Explorer	
  -­‐>	
  New	
  -­‐>	
  Servlet	
  -­‐>	
  Package	
  =	
  
                          com.bookstore.web	
  -­‐>	
  Class	
  Name	
  =	
  BookListServlet	
  -­‐>	
  Click	
  Next	
  -­‐>	
  Remove	
  URL	
  
                          mapping,	
  create	
  new	
  mapping	
  /book/	
  




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Crea8ng	
  your	
  first	
  Servlet	
  (part	
  2)




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookListServlet
                 • Note:	
  This	
  applica8on	
  uses	
  the	
  REST	
  style	
  URL	
  mappings	
  
                          • URLs	
  that	
  end	
  in	
  /	
  imply	
  you	
  are	
  working	
  with	
  a	
  list
                                    • 	
  (like	
  a	
  directory	
  of	
  files).	
  
                          • URI	
  /book/	
  implies	
  a	
  collecBon	
  of	
  books	
  
                                    • Perfect	
  since	
  we	
  want	
  to	
  show	
  a	
  list	
  of	
  books	
  


                 • Modify	
  generated	
  Servlet	
  to	
  only	
  handle	
  the	
  doGet	
  method
                 • Change	
  doGet	
  method	
  to	
  forward	
  to	
  a	
  JSP	
  that	
  we	
  have	
  not	
  
                          created	
  yet	
  that	
  lives	
  in	
  WEB-­‐INF	
  




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
BookListServlet
                • Looks	
  up	
  books	
  using	
  bookRepo	
  (injected	
  with	
  @Inject	
  CDI)
                • Then	
  forward	
  to	
  book-­‐list.jsp	
  to	
  render	
  book	
  lis8ng




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Why	
  JSP	
  is	
  in	
  WEB-­‐INF
                 • WEB-­‐INF	
  is	
  a	
  meta	
  directory	
  folder	
  for	
  war	
  files.	
  
                 • JSPs	
  in	
  WEB-­‐INF	
  folder	
  can	
  never	
  be	
  loaded	
  directly	
  from	
  a	
  
                          browser

                 • This	
  allows	
  us	
  to	
  force	
  all	
  JSPs	
  to	
  first	
  go	
  through	
  our	
  Servlet	
  
                          8er	
  (controllers)	
  which	
  is	
  essen8al	
  for	
  a	
  model	
  2	
  architecture	
  
                          (a	
  form	
  of	
  MVC	
  tailored	
  for	
  HTTP	
  applica8ons),	
  

                 • We	
  use	
  model	
  2	
  throughout	
  the	
  tutorial
                 • 	
  Consider	
  pumng	
  JSPs	
  in	
  WEB-­‐INF	
  a	
  best	
  prac8ce.




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
@WebServlet	
  annota8on	
  (BookListServlet)
                • @WebServlet("/book/")	
  allow	
  us	
  to	
  map	
  this	
  Servlet	
  to	
  handle	
  requests	
  for	
  the	
  URI	
  /
                          book/	
  

                • @WebServlet	
  annota8on	
  is	
  a	
  new	
  feature	
  of	
  Servlets	
  3.0
                • Avoids	
  a	
  lot	
  of	
  XML	
  configura8on




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
@Inject	
  (BookListServlet)
                • Servlet	
  uses	
  repository	
  model	
  object	
  to	
  look	
  up	
  a	
  list	
  of	
  BookRepository	
  books.	
  
                • Java	
  dependency	
  injec8on	
  used	
  to	
  inject	
  BookRepository	
  into	
  the	
  Servlet	
  
                • @Inject	
  etc.	
  added	
  in	
  Java	
  EE	
  6




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
doGet	
  (BookListServlet)
                • Servlet	
  is	
  controller	
  in	
  model	
  2
                • Controller	
  talks	
  to	
  the	
  model	
  (BookRepository	
  to	
  get	
  a	
  list	
  of	
  Book),
                • doGet	
  method	
  gets	
  called	
  when	
  somebody	
  loads	
  the	
  page	
  from	
  the	
  browser	
  and	
  
                          corresponds	
  to	
  HTTP	
  GET

                • doGet	
  method	
  uses	
  the	
  request	
  object	
  (HEpServletRequest	
  request)	
  to	
  put	
  the	
  list	
  of	
  
                          books	
  into	
  request	
  scope	
  using	
  setAEribute	
  as	
  follows:




                                                           request.setAttribute puts books into request scope.
                                                           But what is a scope?

   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Understanding	
  scopes
                 • Servlets	
  and	
  Java	
  EE	
  have	
  various	
  scopes	
  
                 • page,	
  request,	
  conversa8on,	
  session,	
  applica8on
                 • Page	
  scope	
  (10	
  to	
  200	
  milliseconds)
                 • Request	
  scope	
  is	
  around	
  for	
  one	
  HTTP	
  request	
  (1/2	
  second	
  to	
  
                          several	
  seconds)

                 • Session	
  scope	
  is	
  around	
  for	
  the	
  en8re	
  user	
  session	
  (5	
  minutes	
  
                          to	
  90	
  minutes)	
  

                 • Conversa8on	
  scope	
  is	
  around	
  for	
  one	
  workflow	
  (user	
  
                          registra8on,	
  shopping	
  cart,	
  etc.).	
  

                 • Applica8on	
  scope	
  is	
  around	
  un8l	
  web	
  app	
  shuts	
  down
   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Background	
  on	
  JSP
                 • JSP	
  pages	
  are	
  also	
  Servlets
                 • JSP	
  is	
  a	
  templa8ng	
  language	
  to	
  define	
  Servlets	
  that	
  allows	
  
                          you	
  to	
  focus	
  on	
  the	
  HTML	
  instead	
  of	
  the	
  Java	
  code

                 • JSP	
  is	
  like	
  a	
  Servlet	
  turned	
  inside	
  out
                 • Essen8ally	
  a	
  JSP	
  page	
  is	
  translated	
  and	
  compiled	
  into	
  a	
  
                          servlets

                 • JSP	
  is	
  similar	
  to	
  ASP	
  and	
  PHP	
  in	
  concept	
  and	
  scope
                 • ASP	
  predates	
  JSP	
  and	
  early	
  JSP	
  and	
  ASP	
  use	
  a	
  lot	
  of	
  the	
  same	
  
                          concepts	
  



   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
JSP	
  scriptlets	
  versus	
  Templates
                 • JSP	
  allows	
  mixing	
  Java	
  code	
  and	
  HTML	
  (called	
  Java	
  scriptlets),	
  
                          but	
  don’t

                 • JSP	
  adopted	
  more	
  of	
  a	
  classic	
  templa8ng	
  approach	
  like
                          • Freemarker,	
  Velocity	
  and	
  Smarty	
  (PHP	
  based	
  templaBng)	
  
                          • Don’t	
  allow	
  mixing	
  the	
  programming	
  language	
  with	
  the	
  templaBng	
  
                                    language
                          • Allows	
  the	
  templaBng	
  language	
  to	
  be	
  a	
  simple	
  view	
  logic	
  language,
                          • Keeps	
  the	
  templates	
  smaller	
  and	
  more	
  readable.
                 • JSP	
  uses	
  JSTL	
  and	
  the	
  Unified	
  EL	
  to	
  accomplish	
  things	
  that	
  
                          Smarty,	
  Freemarker	
  and	
  Velocity	
  accomplish

                 • Using	
  JSTL/EL	
  instead	
  of	
  Java	
  scriptlets	
  approach	
  is	
  a	
  best	
  
                          prac8ce

   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Crea8ng	
  a	
  JSP	
  in	
  Eclipse
                                                       Create a folder under WebContent/WEB-INF called pages
                                                       Right click WebContent/WEB-INF/pages, then select New->JSP File
                                                       use the file name book-list.jsp




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Modify	
  book-­‐list.jsp	
  to	
  match	
  the	
  following




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
book-­‐list.jsp	
  page	
  direc8ve
                • Let's	
  break	
  this	
  down	
  some.	
  
                • First	
  setup	
  page	
  using	
  JSP	
  page	
  direc8ve:
                • page	
  direc8ve	
  sayshow	
  we	
  want	
  the	
  characters	
  encoded	
  and	
  what	
  the	
  mime	
  type	
  of	
  
                          the	
  page	
  is.	
  Consider	
  it	
  boiler	
  plate	
  for	
  now




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Using	
  JSTL	
  core	
  library
                • Next	
  we	
  import	
  the	
  JSTL	
  core	
  library,	
  under	
  the	
  tag	
  c	
  as	
  follows:




                                HTML background
                                Most of the page is boiler plate and simple HTML. If you are new to
                                HTML, try this HTML tutorial. Then come back here.




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Using	
  JSTL	
  core	
  c:forEach
                • Using	
  c:forEach	
  to	
  iterate	
  through	
  the	
  books	
  in	
  request	
  scope

     !            <c:forEach var="book" items="${books}">
     !            ! <tr>
     !            ! ! <td>${book.title}</td>
     !            ! ! <td>${book.description}</td>
     !            ! ! <td>${book.price}</td>
     !            ! ! <td>${book.pubDate}</td>
     !            ! </tr>
     !            </c:forEach>

     Syntax like${books}, ${book.title}, ${book.price}
     ${book.pubDate} is Unified EL. EL is expression language



   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
JSTL	
  c:forEach
                • Where	
  did	
  the	
  books	
  come	
  from?
                • ${books}	
  is	
  the	
  same	
  books	
  that	
  we	
  put	
  into	
  request	
  scope	
  in	
  the	
  



                  //BookListServlet.doGet method
                ! ! request.setAttribute("books", bookRepo.listBooks());
                !




                                                                                                     !            <c:forEach var="book" items="${books}">
                                                                                                     !            ! <tr>
                                                                                                     !            ! ! <td>${book.title}</td>
                                                                                                     !            ! ! <td>${book.description}</td>
                                                                                                     !            ! ! <td>${book.price}</td>
                                                                                                     !            ! ! <td>${book.pubDate}</td>
                                                                                                     !            ! </tr>
                                                                                                     !            </c:forEach>




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Semng	
  up	
  Java	
  Dependency	
  Injec8on
                • To	
  setup	
  Java	
  Dependency	
  Injec8on	
  (CDI),	
  you	
  need	
  to	
  create	
  a	
  beans.xml	
  file	
  
                • beans.xml	
  need	
  to	
  go	
  into	
  META-­‐INF
                  • META-­‐INF	
  is	
  a	
  special	
  directory	
  for	
  jar	
  files	
  and	
  Java	
  classpath	
  entries	
  to	
  hold	
  
                • 	
  beans.xml	
  can	
  be	
  completely	
  blank	
  or	
  just	
  empty


  $ pwd
  ~/workspace/javaee-tutorial/bookstore/src/META-INF

  $ touch beans.xml


  To get Eclipse to quit complaining about the blank file not having the right format, fill it as follows:


  META-INF/beans.xml


  <?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/
  beans_1_0.xsd">
  </beans>
  Note: the @Inject Java dependency injection will not work without this file.




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Deploying	
  applica8on	
  with	
  Eclipse
                • Deploying	
  with	
  Eclipse
                • Right	
  click	
  the	
  BookListServlet	
  in	
  the	
  Project	
  Explorer
                • Choose	
  Run	
  As-­‐>Run	
  On	
  Server...
                • "Select	
  Manually	
  Define	
  a	
  New	
  Server"
                • Choose	
  Resin-­‐>Resin	
  4.0	
  from	
  the	
  Server	
  List
                • Click	
  "Download	
  addi8onal	
  Server	
  adapters”




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Deploying	
  applica8on	
  with	
  Eclipse
                • Right	
  click	
  BookListServlet	
  in	
  project	
  explorer	
  then	
  choose	
  Run	
  -­‐>	
  Run	
  On	
  Server
                • Select	
  Resin	
  then	
  Click	
  Next-­‐>	
  then	
  click	
  “Download	
  and	
  Install”




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Applica8on	
  Running	
  in	
  Eclipse




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Applica8on	
  Running	
  in	
  FireFox




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
Deploying	
  from	
  the	
  command	
  line




   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12
End	
  of	
  first	
  cookbook	
  in	
  tutorial
                • Cook	
  books	
  and	
  Tutorials
                  • Building	
  a	
  simple	
  lis8ng	
  in	
  JSP:	
  covers	
  model	
  2,	
  Servlets,	
  JSP	
  intro.	
  <You	
  just	
  
                                    finished	
  this	
  one>
                          • Java	
  EE	
  Servlet	
  tutorial	
  :	
  Adding	
  create,	
  update	
  and	
  delete	
  to	
  the	
  bookstore	
  lisBng:	
  
                                    covers	
  more	
  interacBons.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  Using	
  JSPs	
  to	
  create	
  header,	
  footer	
  area,	
  forma>ng,	
  and	
  
                                    basic	
  CSS	
  for	
  bookstore.
                          • Java	
  EE	
  Servlet	
  tutorial	
  :	
  Adding	
  MySQL	
  and	
  JDBC	
  to	
  bookstore	
  example.Java	
  EE	
  
                                    Servlet	
  tutorial	
  :	
  Adding	
  validaBon	
  and	
  JSP	
  tag	
  files	
  to	
  bookstore	
  example.
                          • Java	
  EE	
  Servlet	
  tutorial	
  :	
  Adding	
  I18N	
  support	
  to	
  bookstore	
  example.
                          • Java	
  EE	
  Servlet	
  tutorial	
  :	
  Load	
  tesBng	
  and	
  health	
  monitoring	
  using	
  bookstore	
  
                                    example.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  Se>ng	
  up	
  clustering	
  and	
  session	
  replicaBon.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  Se>ng	
  up	
  security	
  for	
  bookstore	
  example.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  File	
  uploads	
  for	
  bookstore	
  example.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  Using	
  JPA	
  for	
  bookstore	
  example.
                          •         Java	
  EE	
  Servlet	
  tutorial	
  :	
  Using	
  JCache	
  for	
  bookstore	
  example.

   Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server

Thursday, May 3, 12

More Related Content

What's hot

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & StreamsEyal Vardi
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvCodelyTV
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Expressjguerrero999
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019James Newton-King
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionSomya Bagai
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIOctavian Nadolu
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOMMindy McAdams
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 

What's hot (20)

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019gRPC on .NET Core - NDC Sydney 2019
gRPC on .NET Core - NDC Sydney 2019
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPI
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Grails and Ajax
Grails and AjaxGrails and Ajax
Grails and Ajax
 
Jquery
JqueryJquery
Jquery
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 

Viewers also liked

Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2billdigman
 
J2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersJ2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersinTwentyEight Minutes
 
Online Security - The Good, the Bad, and the Crooks
Online Security - The Good, the Bad, and the CrooksOnline Security - The Good, the Bad, and the Crooks
Online Security - The Good, the Bad, and the CrooksSteven Davis
 
2D Art Dalam Video Game - Kudit
2D Art Dalam Video Game  -  Kudit2D Art Dalam Video Game  -  Kudit
2D Art Dalam Video Game - KuditGusti Aditya P
 
Bengkel Gamelan : Press Release 101
Bengkel Gamelan : Press Release 101Bengkel Gamelan : Press Release 101
Bengkel Gamelan : Press Release 101Dennis Ganda
 
Bengkel Gamelan : Pixel Art Best Practices by Wisageni Studio
Bengkel Gamelan : Pixel Art Best Practices by Wisageni StudioBengkel Gamelan : Pixel Art Best Practices by Wisageni Studio
Bengkel Gamelan : Pixel Art Best Practices by Wisageni StudiogamelanYK
 
5 steps into creating your first mobile game
5 steps into creating your first mobile game5 steps into creating your first mobile game
5 steps into creating your first mobile gameDennis Adriansyah Ganda
 
Bengkel 6 pengetahuan dasar audio pada game (1)
Bengkel 6 pengetahuan dasar audio pada game (1)Bengkel 6 pengetahuan dasar audio pada game (1)
Bengkel 6 pengetahuan dasar audio pada game (1)gamelanYK
 
Presentasi seminar mobile games
Presentasi seminar mobile gamesPresentasi seminar mobile games
Presentasi seminar mobile gamesDennis Ganda
 
Guide for better art - ferry marselino
Guide for better art - ferry marselinoGuide for better art - ferry marselino
Guide for better art - ferry marselinoGusti Aditya P
 
Bengkel 5 presentation
Bengkel 5 presentationBengkel 5 presentation
Bengkel 5 presentationgamelanYK
 
Bengkel Gamelan - Unity APK & Asset Size Optimization
Bengkel Gamelan - Unity APK & Asset Size OptimizationBengkel Gamelan - Unity APK & Asset Size Optimization
Bengkel Gamelan - Unity APK & Asset Size OptimizationgamelanYK
 
Basic Version Control Using Git - Bengkel Gamelan
Basic Version Control Using Git - Bengkel GamelanBasic Version Control Using Git - Bengkel Gamelan
Basic Version Control Using Git - Bengkel GamelangamelanYK
 
Introduction into Procedural Content Generation by Yogie Aditya
Introduction into Procedural Content Generation by Yogie AdityaIntroduction into Procedural Content Generation by Yogie Aditya
Introduction into Procedural Content Generation by Yogie AdityagamelanYK
 
Basic Optimization and Unity Tips & Tricks by Yogie Aditya
Basic Optimization and Unity Tips & Tricks by Yogie AdityaBasic Optimization and Unity Tips & Tricks by Yogie Aditya
Basic Optimization and Unity Tips & Tricks by Yogie AdityagamelanYK
 
Presentasi prototype day mobile game advertisement
Presentasi prototype day   mobile game advertisementPresentasi prototype day   mobile game advertisement
Presentasi prototype day mobile game advertisementDennis Ganda
 
Bengkel Gamelan - Game Balancing
Bengkel Gamelan - Game BalancingBengkel Gamelan - Game Balancing
Bengkel Gamelan - Game BalancinggamelanYK
 

Viewers also liked (20)

Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2
 
J2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersJ2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginners
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Online Security - The Good, the Bad, and the Crooks
Online Security - The Good, the Bad, and the CrooksOnline Security - The Good, the Bad, and the Crooks
Online Security - The Good, the Bad, and the Crooks
 
2D Art Dalam Video Game - Kudit
2D Art Dalam Video Game  -  Kudit2D Art Dalam Video Game  -  Kudit
2D Art Dalam Video Game - Kudit
 
Bengkel Gamelan : Press Release 101
Bengkel Gamelan : Press Release 101Bengkel Gamelan : Press Release 101
Bengkel Gamelan : Press Release 101
 
Bengkel Gamelan : Pixel Art Best Practices by Wisageni Studio
Bengkel Gamelan : Pixel Art Best Practices by Wisageni StudioBengkel Gamelan : Pixel Art Best Practices by Wisageni Studio
Bengkel Gamelan : Pixel Art Best Practices by Wisageni Studio
 
5 steps into creating your first mobile game
5 steps into creating your first mobile game5 steps into creating your first mobile game
5 steps into creating your first mobile game
 
Bengkel 6 pengetahuan dasar audio pada game (1)
Bengkel 6 pengetahuan dasar audio pada game (1)Bengkel 6 pengetahuan dasar audio pada game (1)
Bengkel 6 pengetahuan dasar audio pada game (1)
 
Presentasi seminar mobile games
Presentasi seminar mobile gamesPresentasi seminar mobile games
Presentasi seminar mobile games
 
Guide for better art - ferry marselino
Guide for better art - ferry marselinoGuide for better art - ferry marselino
Guide for better art - ferry marselino
 
Bengkel 5 presentation
Bengkel 5 presentationBengkel 5 presentation
Bengkel 5 presentation
 
Bengkel Gamelan - Unity APK & Asset Size Optimization
Bengkel Gamelan - Unity APK & Asset Size OptimizationBengkel Gamelan - Unity APK & Asset Size Optimization
Bengkel Gamelan - Unity APK & Asset Size Optimization
 
Basic Version Control Using Git - Bengkel Gamelan
Basic Version Control Using Git - Bengkel GamelanBasic Version Control Using Git - Bengkel Gamelan
Basic Version Control Using Git - Bengkel Gamelan
 
Introduction into Procedural Content Generation by Yogie Aditya
Introduction into Procedural Content Generation by Yogie AdityaIntroduction into Procedural Content Generation by Yogie Aditya
Introduction into Procedural Content Generation by Yogie Aditya
 
Basic Optimization and Unity Tips & Tricks by Yogie Aditya
Basic Optimization and Unity Tips & Tricks by Yogie AdityaBasic Optimization and Unity Tips & Tricks by Yogie Aditya
Basic Optimization and Unity Tips & Tricks by Yogie Aditya
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Presentasi prototype day mobile game advertisement
Presentasi prototype day   mobile game advertisementPresentasi prototype day   mobile game advertisement
Presentasi prototype day mobile game advertisement
 
Augmented Reality Games
Augmented Reality GamesAugmented Reality Games
Augmented Reality Games
 
Bengkel Gamelan - Game Balancing
Bengkel Gamelan - Game BalancingBengkel Gamelan - Game Balancing
Bengkel Gamelan - Game Balancing
 

Similar to Java EE Servlet JSP Tutorial- Cookbook 1

DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactChen-Tien Tsai
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer ToolsWO Community
 
Boston 2011 OTN Developer Days - GlassFish
Boston 2011 OTN Developer Days - GlassFishBoston 2011 OTN Developer Days - GlassFish
Boston 2011 OTN Developer Days - GlassFishArun Gupta
 
Java EE 6 Clustering with Glassfish 3.1
Java EE 6 Clustering with Glassfish 3.1 Java EE 6 Clustering with Glassfish 3.1
Java EE 6 Clustering with Glassfish 3.1 Shreedhar Ganapathy
 
GlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUGGlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUGArun Gupta
 
Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)Johan Mynhardt
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureArun Gupta
 
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...Arun Gupta
 
Play Framework: Intro & High-Level Overview
Play Framework: Intro & High-Level OverviewPlay Framework: Intro & High-Level Overview
Play Framework: Intro & High-Level OverviewJosh Padnick
 
Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentationdhananajay95
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptKalsoomTahir2
 
CNCF Live Webinar: Low Footprint Java Containers with GraalVM
CNCF Live Webinar: Low Footprint Java Containers with GraalVMCNCF Live Webinar: Low Footprint Java Containers with GraalVM
CNCF Live Webinar: Low Footprint Java Containers with GraalVMLibbySchulze
 
Introduction To J Boss Seam
Introduction To J Boss SeamIntroduction To J Boss Seam
Introduction To J Boss Seamashishkulkarni
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Rajesh Moorjani
 
Servlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpServlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpodilodif
 
nyoug-lxc-december-12-final
nyoug-lxc-december-12-finalnyoug-lxc-december-12-final
nyoug-lxc-december-12-finalGilbert Standen
 
01 web-apps
01 web-apps01 web-apps
01 web-appssnopteck
 

Similar to Java EE Servlet JSP Tutorial- Cookbook 1 (20)

DotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 
Boston 2011 OTN Developer Days - GlassFish
Boston 2011 OTN Developer Days - GlassFishBoston 2011 OTN Developer Days - GlassFish
Boston 2011 OTN Developer Days - GlassFish
 
Java EE 6 Clustering with Glassfish 3.1
Java EE 6 Clustering with Glassfish 3.1 Java EE 6 Clustering with Glassfish 3.1
Java EE 6 Clustering with Glassfish 3.1
 
GlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUGGlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUG
 
Frameworks in java
Frameworks in javaFrameworks in java
Frameworks in java
 
Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for future
 
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
 
Play Framework: Intro & High-Level Overview
Play Framework: Intro & High-Level OverviewPlay Framework: Intro & High-Level Overview
Play Framework: Intro & High-Level Overview
 
Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentation
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
 
CNCF Live Webinar: Low Footprint Java Containers with GraalVM
CNCF Live Webinar: Low Footprint Java Containers with GraalVMCNCF Live Webinar: Low Footprint Java Containers with GraalVM
CNCF Live Webinar: Low Footprint Java Containers with GraalVM
 
Introduction To J Boss Seam
Introduction To J Boss SeamIntroduction To J Boss Seam
Introduction To J Boss Seam
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 
Coursejspservlets00
Coursejspservlets00Coursejspservlets00
Coursejspservlets00
 
Servlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtpServlet and jsp development with eclipse wtp
Servlet and jsp development with eclipse wtp
 
nyoug-lxc-december-12-final
nyoug-lxc-december-12-finalnyoug-lxc-december-12-final
nyoug-lxc-december-12-final
 
01 web-apps
01 web-apps01 web-apps
01 web-apps
 
01 web-apps
01 web-apps01 web-apps
01 web-apps
 

Recently uploaded

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Recently uploaded (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Java EE Servlet JSP Tutorial- Cookbook 1

  • 1. Java  EE  Servlet  Tutorial First Cookbook- Getting started with Model 2: Servlet and JSP Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 2. Open%Source,%Reliable%and%Lightweight% Java%EE%Applica;on%Server% RESIN PRO Web Profile Health System Cloud Support Thursday, May 3, 12
  • 3. Cookbook:  Intro  to  Serlvets  and  JSP • This cookbook in the Java EE Servlet tutorial covers building a simple listing in JSP and Servlets. • This tutorial is part of Java EE Tutorial covering JSP_2.2, and Servlets 3.0. • The WIKI and step by step detailed instructions live here: • http://wiki4.caucho.com/ Building_a_simple_listing_in_JSP Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 4. About  tutorial • Very  liEle  knowledge  of  HTML,  Java  and  JSP  is  assumed • HTML  and  Java  not  covered  length,  but  pointers  in  the  right   direc8on   • Focus  is  Java  Servlets  and  JSP  (Java  Server  Pages) • Use  whatever  IDE  you  would  like,  but  direc8ons  focus  on   Eclipse Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 5. App  you  are  building Sorting Remove Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 6. Sidebar:  Why  Eclipse? • Best?  No  not  really,  best  is  IntelliJ • Eclipse  is  free  and  supports  Java  EE  well • NetBeans  and  JDeveloper  are  from  Oracle,  they  are  good  too Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 7. Running  tutorial  app  in  Eclipse Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 8. Windows?  Try  Linux...   • Java  is  write  once  run  anywhere,  so  you  can  develop  Java  anywhere • Most  companies  deploy  Java  on  some  flavor  of  Linux • You  can  use  Windows  for  development,  but... • Probably  a  good  idea  to  get  familiar  with  produc8on  deployment  environment  anyway • If  you  are  a  Windows  or  OSX  users,  I  suggest  installing  Ubuntu  (hEp:// www.ubuntu.com/)  or  CentOS  on  VMWare  or  Virtual  Box  and  making  that  your  main   development  environment • You  can  make  this  tutorial  work  for  you  on  OSX  and  Windows,  but  might  be  beEer  just   to  go  with  a  fric8onless  approach.  This  way  you  can  focus  on  the  concepts  instead  of   the  configura8on  woes • Cloud  deployment  for  the  most  part  ==  Linux Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 9. Outline • 1 Optional: Getting started Eclipse Java EE IDE • 2 Resources • 3 What is going to be in the project • 4 Creating model and Repository objects for books • 4.1 Book model class • 4.2 Are you new to Java? • 4.3 BookRepository interface • 5 Servlets / JSP • 5.1 Servlet Background • 5.2 Creating your first Servlet • 5.2.1 BookListServlet listing • 5.2.2 Java EE / Servlets scopes (page, request, conversation, session, application) • 6 Creating your first JSP • 6.1 Templates/JSTL versus Java scriptlets • 6.1.1 /WEB-INF/pages/book-list.jsp listing • 6.1.2 HTML background • 6.1.3 JSTL c:forEach • 7 Setting up CDI • 7.1 CDI META-INF/beans.xml • 8 Deploying with Eclipse • 9 Deploying from the command line • 10 Cookbooks and Tutorials Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 10. Using  Eclipse  to  setup  Web  Project • First go here to get Eclipse for Java EE: Install Guide for Eclipse for Java EE Indigo or higher. • Screenshots to follows, but here is the basic steps to installing Eclipse and Java EE development environment in one go • Using Eclipse Indigo or higher Install Resin (lightweight, fast, easy to use Java EE 6 Web Profile server) plugin: 1. Go to File menu -> New Project -> Dynamic Web Project 2. In New Dynamic Web Project Dialog-> New Runtime... 3. In New Runtime Dialog -> Download Additional Server Adapters -> Select Resin (Java EE Web Profile) 4.0.x 4. (Click Next and Ok until it installs Resin runtime) 5. (Eclipse needs to restart) Setup new Web Project in Eclipse 1. File -> New Project -> Dynamic Web Project 2. In New Dynamic Web Project Dialog-> New Runtime...->Select Resin->Check create local server checkbox 3. Step 2 of New Runtime...->Click Download and Install (you only have to do this once) 4. Fill out project name etc. (bookstore). 5. (Click Next and Ok until you are done) Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 11. Install  Java  EE  6  Web  Profile • Go  to  File  menu  -­‐>  New  Project  -­‐>  Dynamic  Web  Project • In  New  Dynamic  Web  Project  Dialog-­‐>  New  Run8me... Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 12. Crea8ng  a  new  web  project • Click  OK  and  Finish  and  Restart  to  restart  Eclipse • Crea8ng  a  new  Web  Project Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 13. Crea8ng  a  simple  Book  lis8ng  for  our  bookstore • Create  a  new  Java  class  as   follows: • Eclipse:  Right  Click  "Java   Resources"  in  Project  Explorer  -­‐>   New  -­‐>  Class  -­‐>  Package   com.bookstore  -­‐>  Class  Name  -­‐>   Book  (That  is  the  last  8me  I  will   tell  you  how  to  create  a  class  in   Eclipse.) • Add  8tle,  descrip8on,  price,   pubDate  and  id  proper8es,  and   the  toString  and  cloneMe   methods  as  follows: Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 14. Are  you  new  to  Java? • If  you  are  new  to  Java  and  the  Book  class  seems  foreign  to   you,   • Read  up  on  Java  a  bit  Official  Java  tutorial.   • Read  the  first  three  trails  (Ge>ng  Started,  Learning  the  Java   Language  and  EssenBal  Java  Classes),   • Skip  ahead  to  Java  Beans.  Skimming  is  ok.   • If  you  have  programmed  before,  most  things  you  will  pick  up  on  your   own. • Then  come  back  here  :) • Reminder:  The  methods  public  String  getId()  and  public  void   setId(String  id)  would  define  a  property  called  id Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 15. Repository  Interface • First  step  in  tutorial  not  going  to  actually  talk  to  a  database   or  use  JDBC • For  now,  just  using  collec8on  API • Repository  object  encapsulates  how  an  object  gets  persisted,   queried  and  updated  (CRUD  opera8ons) • Let’s  define  an  interface  for  our  CRUD  opera8ons • Later  we  use  JDBC/RDBMS  (MySQL),  JTA/RDBMS,  JCache,   MongoDB,  etc.  instead  of  collec8on  API   Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 16. BookRepository  (DAO  like  object) • Eclipse:  Right  Click  "Java  Resources"  in  Project  Explorer  -­‐>  New  -­‐>  Interface  -­‐>  Package   =  com.bookstore  -­‐>  Class  Name  =  Book  -­‐>  Click  Finish Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 17. BookRepositoryImpl  1  of  4 • Actual  BookRepositoryImpl  just  uses  Java  collec8on  to  store  in  memory  (skim  don’t   read)  Set’s  up  some  test  data Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 18. BookRepositoryImpl  2  of  4 • Helper  methods  to  define  test  data,  add  method Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 19. BookRepositoryImpl  3  of  4 • Interface  implementa8ons  using  collec8ons  API Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 20. BookRepositoryImpl  4  of  4 • listBooks  and  removeBooks Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 21. BookRepositoryImpl  wrap  up • This  BookRepositoryImpl  really  basic  class.   • Largely  based  on  the  collec8ons  API • You  can  find  out  more  informa8on  about  the  Java  collec8ons   API  at  this  tutorial  trail.   • A  full  discussion  of  collec8on  API  out  of  scope  for  cookbook • JDBC  cookbook  coming  up  in  this  tutorial  series Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 22. @Applica8onScoped • One  interesBng  thing  is  BookRepositoryImpl  uses   @Applica2onScoped  annotaBon • AnnotaBons  allow  you  to  add  meta-­‐data  to  Java  objects.  (To   learn  more  see  this  annotaBons  tutorial) •  Applica2onScoped  specifies  a  bean  is  applicaBon  scoped • Scoping  defines  a  lifecycle • how  long  an  object  will  be  around • ApplicaBonScoped  means  it  will  be  around  for  the  complete   lifecycle  of  the  Web  ApplicaBon • This annotations has slightly different meanings depending on whether it is used with EJBs or Servlets. This annotation is part of the CDI support added to Java EE 6 to handle Java Dependency Injection. To learn more about CDI go see this tutorial Java Dependency Injection and this one part 2 both written by the same author that is writing this tutorial now. :) Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 23. @Applica8onScoped Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 24. Model  done,  now  controller • Now  that  we  have  a  model   • Book,  BookRepository • Lets  define  our  web  controller   • Servlet  controller   • and  view   • JSPs Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 25. Servlet  Background • A  servlet  is  a  Java  class  that  handles  HTTP  requests • A  Java  web  applica8on  consists  of  one  or  more  servlet   bundled  together  with  any  JSPs  and  Java  classes  it  needs  into   a  war  file  (Web  Applica8on  Archive  file). • Servlets  run  inside  of  a  container  (like  Caucho's  Resin) • End  users  typically  use  a  Java  Web  Applica8on  through  a  web   browser  like  Apple  Safari,  Google  Chrome,  Mozilla  FireFox  or   Internet  Explorer Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 26. Crea8ng  your  first  Servlet • Eclipse:  Right  Click  "Java  Resources"  in  Project  Explorer  -­‐>  New  -­‐>  Servlet  -­‐>  Package  =   com.bookstore.web  -­‐>  Class  Name  =  BookListServlet  -­‐>  Click  Next  -­‐>  Remove  URL   mapping,  create  new  mapping  /book/   Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 27. Crea8ng  your  first  Servlet  (part  2) Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 28. BookListServlet • Note:  This  applica8on  uses  the  REST  style  URL  mappings   • URLs  that  end  in  /  imply  you  are  working  with  a  list •  (like  a  directory  of  files).   • URI  /book/  implies  a  collecBon  of  books   • Perfect  since  we  want  to  show  a  list  of  books   • Modify  generated  Servlet  to  only  handle  the  doGet  method • Change  doGet  method  to  forward  to  a  JSP  that  we  have  not   created  yet  that  lives  in  WEB-­‐INF   Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 29. BookListServlet • Looks  up  books  using  bookRepo  (injected  with  @Inject  CDI) • Then  forward  to  book-­‐list.jsp  to  render  book  lis8ng Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 30. Why  JSP  is  in  WEB-­‐INF • WEB-­‐INF  is  a  meta  directory  folder  for  war  files.   • JSPs  in  WEB-­‐INF  folder  can  never  be  loaded  directly  from  a   browser • This  allows  us  to  force  all  JSPs  to  first  go  through  our  Servlet   8er  (controllers)  which  is  essen8al  for  a  model  2  architecture   (a  form  of  MVC  tailored  for  HTTP  applica8ons),   • We  use  model  2  throughout  the  tutorial •  Consider  pumng  JSPs  in  WEB-­‐INF  a  best  prac8ce. Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 31. @WebServlet  annota8on  (BookListServlet) • @WebServlet("/book/")  allow  us  to  map  this  Servlet  to  handle  requests  for  the  URI  / book/   • @WebServlet  annota8on  is  a  new  feature  of  Servlets  3.0 • Avoids  a  lot  of  XML  configura8on Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 32. @Inject  (BookListServlet) • Servlet  uses  repository  model  object  to  look  up  a  list  of  BookRepository  books.   • Java  dependency  injec8on  used  to  inject  BookRepository  into  the  Servlet   • @Inject  etc.  added  in  Java  EE  6 Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 33. doGet  (BookListServlet) • Servlet  is  controller  in  model  2 • Controller  talks  to  the  model  (BookRepository  to  get  a  list  of  Book), • doGet  method  gets  called  when  somebody  loads  the  page  from  the  browser  and   corresponds  to  HTTP  GET • doGet  method  uses  the  request  object  (HEpServletRequest  request)  to  put  the  list  of   books  into  request  scope  using  setAEribute  as  follows: request.setAttribute puts books into request scope. But what is a scope? Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 34. Understanding  scopes • Servlets  and  Java  EE  have  various  scopes   • page,  request,  conversa8on,  session,  applica8on • Page  scope  (10  to  200  milliseconds) • Request  scope  is  around  for  one  HTTP  request  (1/2  second  to   several  seconds) • Session  scope  is  around  for  the  en8re  user  session  (5  minutes   to  90  minutes)   • Conversa8on  scope  is  around  for  one  workflow  (user   registra8on,  shopping  cart,  etc.).   • Applica8on  scope  is  around  un8l  web  app  shuts  down Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 35. Background  on  JSP • JSP  pages  are  also  Servlets • JSP  is  a  templa8ng  language  to  define  Servlets  that  allows   you  to  focus  on  the  HTML  instead  of  the  Java  code • JSP  is  like  a  Servlet  turned  inside  out • Essen8ally  a  JSP  page  is  translated  and  compiled  into  a   servlets • JSP  is  similar  to  ASP  and  PHP  in  concept  and  scope • ASP  predates  JSP  and  early  JSP  and  ASP  use  a  lot  of  the  same   concepts   Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 36. JSP  scriptlets  versus  Templates • JSP  allows  mixing  Java  code  and  HTML  (called  Java  scriptlets),   but  don’t • JSP  adopted  more  of  a  classic  templa8ng  approach  like • Freemarker,  Velocity  and  Smarty  (PHP  based  templaBng)   • Don’t  allow  mixing  the  programming  language  with  the  templaBng   language • Allows  the  templaBng  language  to  be  a  simple  view  logic  language, • Keeps  the  templates  smaller  and  more  readable. • JSP  uses  JSTL  and  the  Unified  EL  to  accomplish  things  that   Smarty,  Freemarker  and  Velocity  accomplish • Using  JSTL/EL  instead  of  Java  scriptlets  approach  is  a  best   prac8ce Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 37. Crea8ng  a  JSP  in  Eclipse Create a folder under WebContent/WEB-INF called pages Right click WebContent/WEB-INF/pages, then select New->JSP File use the file name book-list.jsp Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 38. Modify  book-­‐list.jsp  to  match  the  following Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 39. book-­‐list.jsp  page  direc8ve • Let's  break  this  down  some.   • First  setup  page  using  JSP  page  direc8ve: • page  direc8ve  sayshow  we  want  the  characters  encoded  and  what  the  mime  type  of   the  page  is.  Consider  it  boiler  plate  for  now Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 40. Using  JSTL  core  library • Next  we  import  the  JSTL  core  library,  under  the  tag  c  as  follows: HTML background Most of the page is boiler plate and simple HTML. If you are new to HTML, try this HTML tutorial. Then come back here. Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 41. Using  JSTL  core  c:forEach • Using  c:forEach  to  iterate  through  the  books  in  request  scope ! <c:forEach var="book" items="${books}"> ! ! <tr> ! ! ! <td>${book.title}</td> ! ! ! <td>${book.description}</td> ! ! ! <td>${book.price}</td> ! ! ! <td>${book.pubDate}</td> ! ! </tr> ! </c:forEach> Syntax like${books}, ${book.title}, ${book.price} ${book.pubDate} is Unified EL. EL is expression language Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 42. JSTL  c:forEach • Where  did  the  books  come  from? • ${books}  is  the  same  books  that  we  put  into  request  scope  in  the   //BookListServlet.doGet method ! ! request.setAttribute("books", bookRepo.listBooks()); ! ! <c:forEach var="book" items="${books}"> ! ! <tr> ! ! ! <td>${book.title}</td> ! ! ! <td>${book.description}</td> ! ! ! <td>${book.price}</td> ! ! ! <td>${book.pubDate}</td> ! ! </tr> ! </c:forEach> Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 43. Semng  up  Java  Dependency  Injec8on • To  setup  Java  Dependency  Injec8on  (CDI),  you  need  to  create  a  beans.xml  file   • beans.xml  need  to  go  into  META-­‐INF • META-­‐INF  is  a  special  directory  for  jar  files  and  Java  classpath  entries  to  hold   •  beans.xml  can  be  completely  blank  or  just  empty $ pwd ~/workspace/javaee-tutorial/bookstore/src/META-INF $ touch beans.xml To get Eclipse to quit complaining about the blank file not having the right format, fill it as follows: META-INF/beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ beans_1_0.xsd"> </beans> Note: the @Inject Java dependency injection will not work without this file. Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 44. Deploying  applica8on  with  Eclipse • Deploying  with  Eclipse • Right  click  the  BookListServlet  in  the  Project  Explorer • Choose  Run  As-­‐>Run  On  Server... • "Select  Manually  Define  a  New  Server" • Choose  Resin-­‐>Resin  4.0  from  the  Server  List • Click  "Download  addi8onal  Server  adapters” Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 45. Deploying  applica8on  with  Eclipse • Right  click  BookListServlet  in  project  explorer  then  choose  Run  -­‐>  Run  On  Server • Select  Resin  then  Click  Next-­‐>  then  click  “Download  and  Install” Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 46. Applica8on  Running  in  Eclipse Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 47. Applica8on  Running  in  FireFox Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 48. Deploying  from  the  command  line Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12
  • 49. End  of  first  cookbook  in  tutorial • Cook  books  and  Tutorials • Building  a  simple  lis8ng  in  JSP:  covers  model  2,  Servlets,  JSP  intro.  <You  just   finished  this  one> • Java  EE  Servlet  tutorial  :  Adding  create,  update  and  delete  to  the  bookstore  lisBng:   covers  more  interacBons. • Java  EE  Servlet  tutorial  :  Using  JSPs  to  create  header,  footer  area,  forma>ng,  and   basic  CSS  for  bookstore. • Java  EE  Servlet  tutorial  :  Adding  MySQL  and  JDBC  to  bookstore  example.Java  EE   Servlet  tutorial  :  Adding  validaBon  and  JSP  tag  files  to  bookstore  example. • Java  EE  Servlet  tutorial  :  Adding  I18N  support  to  bookstore  example. • Java  EE  Servlet  tutorial  :  Load  tesBng  and  health  monitoring  using  bookstore   example. • Java  EE  Servlet  tutorial  :  Se>ng  up  clustering  and  session  replicaBon. • Java  EE  Servlet  tutorial  :  Se>ng  up  security  for  bookstore  example. • Java  EE  Servlet  tutorial  :  File  uploads  for  bookstore  example. • Java  EE  Servlet  tutorial  :  Using  JPA  for  bookstore  example. • Java  EE  Servlet  tutorial  :  Using  JCache  for  bookstore  example. Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server Thursday, May 3, 12