Java EE Servlet/JSP Tutorial- Cookbook 2

B
Java	
  EE	
  Servlet/JSP	
  Tutorial

                                                       Second cookbook, getting started with Model 2: Servlet and JSP
                                                       Implementing the Edit/Update, Add




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Cookbook:	
  Intro	
  to	
  Serlvets	
  and	
  JSP
              • This cookbook in the Java EE Servlet /JSP tutorial
                       covers building CRUD Operations in a Model 2
                       architecture

              • This is a continuation of Building a simple listing in
                       JSP using Java EE and Servlets (Part 1).

              • This	
  is	
  part	
  2,	
  must	
  do	
  part	
  1	
  first
                • Part	
  1	
  Slides
              • Covers	
  working	
  with	
  Servlet	
  doGet/doPost	
  methods,	
  JSTL,	
  
                       redirec8on	
  versus	
  forwarding




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Redux:	
  About	
  tutorial
              • Very	
  liNle	
  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
Redux:	
  App	
  you	
  are	
  building
                                                                                                                                    Sorting




                                                                                                                                              Remove




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Outline
           • 1 Java EE Servlet Tutorial: Implementing a basic CRUD listing
           • 2 Adding a link to the book listing to edit a book
              • 2.1 Adding an edit book link to book-list.jsp listing
           • 3 Adding a link to the book listing to add a book
              • 3.1 Adding an add book link to book-list.jsp listing
           • 4 Servlet doGet to load a Book form
              • 4.1 BookEditorServlet.java doGet
              • 4.2 BookEditorServlet.java doGet() delegate to book-form.jsp page
              • 4.3 BookEditorServlet.java doGet() delegate to book-form.jsp page
           • 5 Rendering the book form HTML
              • 5.1 book-form.jsp Renders form to update or add a Book
              • 5.2 book-form.jsp using JSTL c:choose to display update or add status
              • 5.3 book-form.jsp using JSTL c:if to hidden id field for edit/update operation
           • 6 Creating a doPost method to handle the form submission
              • 6.1 BookEditorServlet.java doPost
           • 7 Quick review of what we have so far
              • 7.1 ./WebContent/WEB-INF/pages/book-form.jsp full listing
              • 7.2 ./WebContent/WEB-INF/pages/book-list.jsp full listing
              • 7.3 ./src/META-INF/beans.xml full listing
              • 7.4 ./src/com/bookstore/Book.java
              • 7.5 ./src/com/bookstore/BookRepositoryImpl.java full listing (testing only)
              • 7.6 ./src/com/bookstore/BookRepository.java full listing
              • 7.7 ./src/com/bookstore/web/BookEditorServlet.java
              • 7.8 ./src/com/bookstore/web/BookListServlet.java
           • 8 Technical debt
           • 9 Cookbooks and Tutorials

Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Where	
  we	
  leX	
  off	
  in	
  last	
  example
              • BookListServlet	
  uses	
  a	
  BookRepository	
  object	
  (DAO)	
  to	
  load	
  a	
  
                       list	
  of	
  books	
  

              • BookListServlet	
  then	
  delegated	
  to	
  book-­‐list.jsp	
  to	
  render	
  the	
  
                       book	
  lis8ng	
  with	
  JSTL	
  and	
  Unified	
  EL

              • In	
  this	
  cookbook,	
  
                       • add	
  a	
  link	
  to	
  the	
  book	
  lis9ng	
  for	
  edi9ng	
  a	
  book
                       • add	
  a	
  link	
  so	
  that	
  the	
  end	
  user	
  can	
  add	
  a	
  new	
  book	
  to	
  the	
  lis9ng
                       • Create	
  backend	
  Servlets	
  to	
  handle	
  new	
  links	
  on	
  book	
  lis9ng




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Model	
  2	
  MVC
Model                                                                                                              View                          Controller
                                                                                                                                                   •BookListingServlet
  •Book                                                                                                                 •book-form.jsp             •BookEditorServlet
  •BookRepositoryImpl                                                                                                   •book-list.jsp
  •BookRepository




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Add	
  a	
  new	
  link	
  to	
  book-­‐lis8ng.jsp
             • Add	
  link	
  to	
  edit	
  opera8on
             • Edit	
  opera8on	
  pulls	
  up	
  form	
  with	
  details	
  of	
  Book	
  8tle	
  that	
  is	
  clicked
             • Uses	
  <a	
  href=””
             • Uses	
  expression	
  pageContext.request.contextPath/book	
  to	
  address	
  new	
  Edit	
  Servlet
             • Servlet	
  created	
  later,	
  id	
  parameter	
  implies	
  edit	
  opertaion
             • EL	
  expression	
  pageContext.request.contextPath	
  refers	
  to	
  the	
  URI,	
  web	
  app	
  (war	
  file)	
  is	
  
                       mapped	
  to	
  in	
  Servlet	
  container




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Edit	
  Link	
  on	
  Title




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
What	
  gets	
  rendered
             • The	
  following	
  links	
  with	
  URI	
  (/bookstore)	
  of	
  webapp	
  get	
  rendered	
  when	
  book-­‐
                       lis8ng.jsp	
  loads




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Adding	
  a	
  “add	
  a	
  book”	
  link	
  to	
  book	
  lis8ng




     • Now	
  that	
  links	
  are	
  going	
  to	
  URI	
  /book,	
  
     • You	
  need	
  a	
  Servlet	
  that	
  handles	
  links
       • For	
  add	
  opera9on	
  and	
  edit	
  opera9on
     • New	
  BookEditorServlet	
  will	
  handle	
  both	
  add	
  and	
  edit	
  book	
  func8ons




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Add	
  Link	
  Above	
  Table




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
BookEditorServlet
              • @WebServlet("/book")	
  maps	
  BookEditorServlet	
  to	
  the	
  URI	
  /
                       book

              • Common	
  to	
  load	
  a	
  form	
  from	
  a	
  doGet	
  method,	
  and	
  to	
  handle	
  
                       the	
  form	
  submission	
  via	
  doPost

              • Follows	
  REST	
  and	
  HTTP	
  principles	
  GET	
  opera8ons	
  reads	
  data,	
  
                       • later	
  POST	
  data	
  modifies	
  data
              • doGet	
  method	
  uses	
  id	
  being	
  empty	
  or	
  not	
  to	
  
                       • determine	
  if	
  this	
  is	
  a	
  load	
  "Add	
  Book	
  Form"	
  or	
  
                       • load	
  "Update	
  Book	
  Form"	
  opera9on




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




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
BookEditorServlet.doGet	
  loads	
  edit/add	
  form
                                                                                                                                    Add Link


                                                                                                                                    Edit Link




                                                                                                     doGet is load form operation


                                                                                                                                                book-form.jsp




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Model	
  2	
  and	
  BookEditorServlet.doGet
             • In	
  Model	
  2,	
  Servlets	
  (controllers/ac8ons)	
  prepares	
  model	
  data	
  for	
  the	
  view
             • This	
  includes	
  date	
  formagng




                                                   Notice “book” is mapped into request scope

                                                   “book” will get used from book-form.jsp




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Model	
  2	
  and	
  BookEditorServlet.doGet	
  (cont)
             • To	
  render	
  the	
  HTML	
  form,	
  the	
  servlet	
  delegates	
  to	
  book-­‐form.jsp




                                                                                                                                    book-form.jsp




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
book-­‐form.jsp	
  (1	
  of	
  3)
             • book-­‐form.jsp	
  renders	
  form	
  to	
  edit	
  book	
  
             • If	
  book.id	
  present	
  then	
  edit	
  opera8on,	
  otherwise	
  add	
  opera8on
               • JSTL	
  c:choose,	
  c:otherwise	
  to	
  display	
  correct	
  9tle	
  based	
  on	
  Update	
  (Edit)	
  or	
  Add	
  
                                 opera9on




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
book-­‐form.jsp	
  (2	
  of	
  3)
             • Uses	
  Unified	
  EL	
  to	
  render	
  values	
  and	
  then	
  just	
  plain	
  HTML	
  for	
  form	
  fields




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
book-­‐form.jsp	
  (3	
  of	
  3)
             • hidden	
  id	
  property	
  is	
  rendered	
  if	
  edit	
  (Update)	
  opera8on
             • Cancel	
  buNon	
  takes	
  them	
  back	
  to	
  lis8ng	
  (/book/	
  is	
  lis8ng).
             • Submit	
  buNon	
  POST	
  form	
  to	
  BookEditorServlet.doPost	
  (defined	
  next)




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
BookEditorServlet.doPost()
              • if	
  id	
  request	
  parameter	
  is	
  null	
  then	
  BookEditorServlet.doPost	
  
                       calls	
  bookRepo.addBook,	
  
                       • otherwise	
  it	
  calls	
  bookRepo.updateBook
              • 	
  Then,	
  doPost	
  redirects	
  to	
  /book/
                       • redirect	
  means	
  an	
  extra	
  hit	
  to	
  the	
  server,	
  
                       • basically	
  telling	
  browser	
  to	
  load	
  another	
  link
                       • Not	
  forward	
  like	
  before	
  because	
  of	
  bookmarking
                       • Remember	
  URL	
  /book/	
  (ending	
  in	
  slash)	
  represents	
  a	
  collec9on	
  of	
  
                                 books,	
  while	
  /book	
  (no	
  slash)	
  represents	
  a	
  single	
  book	
  
                       • If	
  doPost	
  did	
  a	
  forward,	
  then	
  browser	
  would	
  show	
  wrong	
  link	
  for	
  
                                 lis9ng
                       • Use	
  sendRedirect	
  instead	
  of	
  a	
  forward	
  for	
  bookmarking


Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
BookEditorServlet.doPost()




Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
BookEditorServlet.doPost
                                                                                                                                                      book-form.jsp




                                                                                                                                    BookListServlet
Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Review	
  of	
  CRUD	
  lis8ng
  • Book	
  Form
                                                                                      • Servlet	
  that	
  loads	
  Book	
  (doGet)	
  form	
  
    • ./WebContent/WEB-­‐INF/pages/book-­‐form.jsp	
  	
  	
  	
  	
  	
  	
  	
  	
   and	
  handles	
  Book	
  form	
  submissions	
  
                                                                                                                                                                      (doPost).
  • Book	
  Lis8ng
    • ./WebContent/WEB-­‐INF/pages/book-­‐list.jsp	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
   ./src/com/bookstore/web/
                                                                                                                                                                      BookEditorServlet.java	
  	
  	
  	
  	
  	
  
  • Needed	
  for	
  Java	
  EE	
  dependency	
  injec8on	
  (CDI)
    • ./src/META-­‐INF/beans.xml	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
   • Servlet	
  that	
  looks	
  up	
  a	
  list	
  of	
  books	
  and	
  
                                                                                                                                                                      displays	
  the	
  lis8ng
  • Domain/model	
  object
                                                                                                                                                                      ./src/com/bookstore/web/
    • ./src/com/bookstore/Book.java	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
     BookListServlet.java	
  	
  	
  	
  	
  	
  	
  	
  	
  

  • Repository	
  implementa8on	
  using	
  Java	
  collec8ons	
  
           (just	
  for	
  tes8ng)
           • ./src/com/bookstore/BookRepositoryImpl.java	
  	
  	
  	
  	
  	
  	
  	
  
  • Interface	
  to	
  Book	
  Repository	
  so	
  we	
  can	
  swap	
  it	
  out	
  
           with	
  JDBC,	
  JPA,	
  JCache	
  and	
  MongoDB	
  version	
  later
           • ./src/com/bookstore/BookRepository.java	
  	
  	
  	
  	
  	
  	
  
Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
Open%Source,%Reliable%and%Lightweight%
       Java%EE%Applica;on%Server%




RESIN PRO   Web Profile   Health System   Cloud Support
More	
  Info

         • Caucho	
  Technology	
  |	
  Home	
  Page
         • Resin	
  |	
  Applica8on	
  Server
         • Resin	
  |	
  Java	
  EE	
  Web	
  Profile	
  Applica8on	
  Server
         • Resin	
  -­‐	
  Cloud	
  Support	
  |	
  3G	
  -­‐	
  Java	
  Clustering
         • Resin	
  |	
  Java	
  CDI	
  |	
  Dependency	
  Injec8on	
  /	
  IoC
         • Resin	
  -­‐	
  Health	
  System	
  |	
  Java	
  Monitoring	
  and	
  Server	
  Monitoring
         • Download	
  Resin	
  |	
  Applica8on	
  Server
         • Watch	
  Resin	
  |	
  Applica8on	
  Server	
  Featured	
  Video

Caucho	
  Home	
  	
  |	
  	
  Contact	
  Us	
  	
  |	
  	
  Caucho	
  Blog	
  	
  |	
  	
  Wiki	
  	
  |	
  Applica8on	
  Server
1 of 26

Recommended

Java EE Servlet JSP Tutorial- Cookbook 1 by
Java EE Servlet JSP Tutorial- Cookbook 1Java EE Servlet JSP Tutorial- Cookbook 1
Java EE Servlet JSP Tutorial- Cookbook 1billdigman
8.8K views49 slides
Resin Outperforms NginX by
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginXbilldigman
3.1K views20 slides
Alfresco monitoring with Nagios and ELK stack by
Alfresco monitoring with Nagios and ELK stackAlfresco monitoring with Nagios and ELK stack
Alfresco monitoring with Nagios and ELK stackCesar Capillas
1.4K views22 slides
Using Apache Camel as AKKA by
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
6.2K views50 slides
Reactor grails realtime web devoxx 2013 by
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013Stéphane Maldini
4.2K views90 slides
Event Driven Architecture with Apache Camel by
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camelprajods
7.1K views35 slides

More Related Content

What's hot

Building Asynchronous Applications by
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
633 views46 slides
Developing Microservices with Apache Camel by
Developing Microservices with Apache CamelDeveloping Microservices with Apache Camel
Developing Microservices with Apache CamelClaus Ibsen
6.8K views101 slides
ActiveMQ Performance Tuning by
ActiveMQ Performance TuningActiveMQ Performance Tuning
ActiveMQ Performance TuningChristian Posta
15K views55 slides
Full stack development with node and NoSQL - All Things Open - October 2017 by
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
368 views52 slides
Simplify your integrations with Apache Camel by
Simplify your integrations with Apache CamelSimplify your integrations with Apache Camel
Simplify your integrations with Apache CamelKenneth Peeples
4.2K views54 slides
Apache Camel - FUSE community day London 2010 presentation by
Apache Camel - FUSE community day London 2010 presentationApache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentationClaus Ibsen
2.3K views93 slides

What's hot(20)

Building Asynchronous Applications by Johan Edstrom
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
Johan Edstrom633 views
Developing Microservices with Apache Camel by Claus Ibsen
Developing Microservices with Apache CamelDeveloping Microservices with Apache Camel
Developing Microservices with Apache Camel
Claus Ibsen6.8K views
Full stack development with node and NoSQL - All Things Open - October 2017 by Matthew Groves
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves368 views
Simplify your integrations with Apache Camel by Kenneth Peeples
Simplify your integrations with Apache CamelSimplify your integrations with Apache Camel
Simplify your integrations with Apache Camel
Kenneth Peeples4.2K views
Apache Camel - FUSE community day London 2010 presentation by Claus Ibsen
Apache Camel - FUSE community day London 2010 presentationApache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentation
Claus Ibsen2.3K views
Profiling JavaScript Performance by FITC
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
FITC458 views
Polyglot Messaging with Apache ActiveMQ by Christian Posta
Polyglot Messaging with Apache ActiveMQPolyglot Messaging with Apache ActiveMQ
Polyglot Messaging with Apache ActiveMQ
Christian Posta3.3K views
Why jakarta ee matters (ConFoo 2021) by Ryan Cuprak
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak221 views
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook by JAX London
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
JAX London1.5K views
Apache Camel Introduction & What's in the box by Claus Ibsen
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen4.8K views
Crank Up Your Apps With TorqueBox by Jim Crossley
Crank Up Your Apps With TorqueBoxCrank Up Your Apps With TorqueBox
Crank Up Your Apps With TorqueBox
Jim Crossley3.7K views
Torquebox @ Charlotte.rb May 2011 by tobiascrawley
Torquebox @ Charlotte.rb May 2011Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011
tobiascrawley775 views
Developing, Testing and Scaling with Apache Camel - UberConf 2015 by Matt Raible
Developing, Testing and Scaling with Apache Camel - UberConf 2015Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015
Matt Raible26K views
HyperLight Websites by FITC
HyperLight WebsitesHyperLight Websites
HyperLight Websites
FITC504 views
Faster java ee builds with gradle [con4921] by Ryan Cuprak
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak2.4K views
FITC - Here Be Dragons: Advanced JavaScript Debugging by Rami Sayar
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
Rami Sayar1.1K views
A year in the life of a Grails startup by tomaslin
A year in the life of a Grails startupA year in the life of a Grails startup
A year in the life of a Grails startup
tomaslin2.7K views
Enterprise Integration Patterns with Apache Camel by Ioan Eugen Stan
Enterprise Integration Patterns with Apache CamelEnterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache Camel
Ioan Eugen Stan9.2K views

Viewers also liked

Jsp chapter 1 by
Jsp chapter 1Jsp chapter 1
Jsp chapter 1kamal kotecha
10.9K views13 slides
Web Component Development with Servlet and JSP Technologies Unit 01 by
Web Component Development with Servlet and JSP Technologies Unit 01Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01Prashanth Shivakumar
1.9K views25 slides
Iaetsd a survey of various design patterns for improving quality and by
Iaetsd a survey of various design patterns for improving quality andIaetsd a survey of various design patterns for improving quality and
Iaetsd a survey of various design patterns for improving quality andIaetsd Iaetsd
338 views5 slides
Model-Driven Development of Web Applications by
Model-Driven Development of Web ApplicationsModel-Driven Development of Web Applications
Model-Driven Development of Web Applicationsidescitation
634 views8 slides
J2ee (java ee) tutorial for beginners by
J2ee (java ee) tutorial for beginnersJ2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersinTwentyEight Minutes
3.9K views45 slides
Servidores web by
Servidores webServidores web
Servidores webOthon Oliveira
144 views77 slides

Viewers also liked(20)

Web Component Development with Servlet and JSP Technologies Unit 01 by Prashanth Shivakumar
Web Component Development with Servlet and JSP Technologies Unit 01Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01
Iaetsd a survey of various design patterns for improving quality and by Iaetsd Iaetsd
Iaetsd a survey of various design patterns for improving quality andIaetsd a survey of various design patterns for improving quality and
Iaetsd a survey of various design patterns for improving quality and
Iaetsd Iaetsd338 views
Model-Driven Development of Web Applications by idescitation
Model-Driven Development of Web ApplicationsModel-Driven Development of Web Applications
Model-Driven Development of Web Applications
idescitation634 views
Web engineering 2(lect 0) by Roohul Amin
Web engineering 2(lect 0)Web engineering 2(lect 0)
Web engineering 2(lect 0)
Roohul Amin3.7K views
Web engineering 2(lect 2) by Roohul Amin
Web engineering 2(lect 2)Web engineering 2(lect 2)
Web engineering 2(lect 2)
Roohul Amin660 views
OOWS 2.0: A Model-driven Web Engineering Method for the Development of Web 2.... by Paco Valverde
OOWS 2.0: A Model-driven Web Engineering Method for the Development of Web 2....OOWS 2.0: A Model-driven Web Engineering Method for the Development of Web 2....
OOWS 2.0: A Model-driven Web Engineering Method for the Development of Web 2....
Paco Valverde1.7K views
Créer une application web en asp.net mvc 2 by Novencia Groupe
Créer une application web en asp.net mvc 2Créer une application web en asp.net mvc 2
Créer une application web en asp.net mvc 2
Novencia Groupe3.7K views
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP) by JavaEE Trainers
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
JavaEE Trainers2.4K views
Basic Version Control Using Git - Bengkel Gamelan by gamelanYK
Basic Version Control Using Git - Bengkel GamelanBasic Version Control Using Git - Bengkel Gamelan
Basic Version Control Using Git - Bengkel Gamelan
gamelanYK693 views
2D Art Dalam Video Game - Kudit by Gusti Aditya P
2D Art Dalam Video Game  -  Kudit2D Art Dalam Video Game  -  Kudit
2D Art Dalam Video Game - Kudit
Gusti Aditya P2.1K views
Online Security - The Good, the Bad, and the Crooks by Steven Davis
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
Steven Davis1.1K views
Presentasi seminar mobile games by Dennis Ganda
Presentasi seminar mobile gamesPresentasi seminar mobile games
Presentasi seminar mobile games
Dennis Ganda2.7K views
Bengkel 6 pengetahuan dasar audio pada game (1) by gamelanYK
Bengkel 6 pengetahuan dasar audio pada game (1)Bengkel 6 pengetahuan dasar audio pada game (1)
Bengkel 6 pengetahuan dasar audio pada game (1)
gamelanYK667 views
Bengkel Gamelan : Press Release 101 by Dennis Ganda
Bengkel Gamelan : Press Release 101Bengkel Gamelan : Press Release 101
Bengkel Gamelan : Press Release 101
Dennis Ganda2.1K views

Similar to Java EE Servlet/JSP Tutorial- Cookbook 2

Coursejspservlets00 by
Coursejspservlets00Coursejspservlets00
Coursejspservlets00Rajesh Moorjani
316 views21 slides
Jeetrainers.com coursejspservlets00 by
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Rajesh Moorjani
270 views21 slides
DotNet MVC and webpack + Babel + react by
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + reactChen-Tien Tsai
2.7K views35 slides
Show Some Spine! by
Show Some Spine!Show Some Spine!
Show Some Spine!Geoff Gerrietts
582 views22 slides
PLAT-8 Spring Web Scripts and Spring Surf by
PLAT-8 Spring Web Scripts and Spring SurfPLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring SurfAlfresco Software
1.5K views25 slides
React js Online Training by
React js Online TrainingReact js Online Training
React js Online TrainingLearntek1
169 views21 slides

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

Jeetrainers.com coursejspservlets00 by Rajesh Moorjani
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
Rajesh Moorjani270 views
DotNet MVC and webpack + Babel + react by Chen-Tien Tsai
DotNet MVC and webpack + Babel + reactDotNet MVC and webpack + Babel + react
DotNet MVC and webpack + Babel + react
Chen-Tien Tsai2.7K views
PLAT-8 Spring Web Scripts and Spring Surf by Alfresco Software
PLAT-8 Spring Web Scripts and Spring SurfPLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
Alfresco Software1.5K views
React js Online Training by Learntek1
React js Online TrainingReact js Online Training
React js Online Training
Learntek1169 views
React-Js-Online-Training-9028522.ppsx by Kulbir4
React-Js-Online-Training-9028522.ppsxReact-Js-Online-Training-9028522.ppsx
React-Js-Online-Training-9028522.ppsx
Kulbir423 views
04 integrate entityframework by Erhwen Kuo
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
Erhwen Kuo653 views
Introduction to Cooking with Chef by John Osborne
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with Chef
John Osborne717 views
Streaming to a New Jakarta EE by J On The Beach
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
J On The Beach214 views
Streaming to a new Jakarta EE by Markus Eisele
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
Markus Eisele961 views
Ppt for Online music store by ADEEBANADEEM
Ppt for Online music storePpt for Online music store
Ppt for Online music store
ADEEBANADEEM3.7K views
005432796.pdf by EidTahir
005432796.pdf005432796.pdf
005432796.pdf
EidTahir1 view
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines by Lauren Yew
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Lauren Yew135 views
Service-Oriented Design and Implement with Rails3 by Wen-Tien Chang
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang4.5K views
React.js for Rails Developers by Arkency
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
Arkency2.4K views

Recently uploaded

"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
53 views29 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
90 views46 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
93 views15 slides
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericShapeBlue
88 views9 slides
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueShapeBlue
176 views20 slides
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineShapeBlue
181 views19 slides

Recently uploaded(20)

"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue181 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu365 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc160 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue123 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software385 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10126 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue138 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li80 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue140 views

Java EE Servlet/JSP Tutorial- Cookbook 2

  • 1. Java  EE  Servlet/JSP  Tutorial Second cookbook, getting started with Model 2: Servlet and JSP Implementing the Edit/Update, Add Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 2. Cookbook:  Intro  to  Serlvets  and  JSP • This cookbook in the Java EE Servlet /JSP tutorial covers building CRUD Operations in a Model 2 architecture • This is a continuation of Building a simple listing in JSP using Java EE and Servlets (Part 1). • This  is  part  2,  must  do  part  1  first • Part  1  Slides • Covers  working  with  Servlet  doGet/doPost  methods,  JSTL,   redirec8on  versus  forwarding Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 3. Redux:  About  tutorial • Very  liNle  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
  • 4. Redux:  App  you  are  building Sorting Remove Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 5. Outline • 1 Java EE Servlet Tutorial: Implementing a basic CRUD listing • 2 Adding a link to the book listing to edit a book • 2.1 Adding an edit book link to book-list.jsp listing • 3 Adding a link to the book listing to add a book • 3.1 Adding an add book link to book-list.jsp listing • 4 Servlet doGet to load a Book form • 4.1 BookEditorServlet.java doGet • 4.2 BookEditorServlet.java doGet() delegate to book-form.jsp page • 4.3 BookEditorServlet.java doGet() delegate to book-form.jsp page • 5 Rendering the book form HTML • 5.1 book-form.jsp Renders form to update or add a Book • 5.2 book-form.jsp using JSTL c:choose to display update or add status • 5.3 book-form.jsp using JSTL c:if to hidden id field for edit/update operation • 6 Creating a doPost method to handle the form submission • 6.1 BookEditorServlet.java doPost • 7 Quick review of what we have so far • 7.1 ./WebContent/WEB-INF/pages/book-form.jsp full listing • 7.2 ./WebContent/WEB-INF/pages/book-list.jsp full listing • 7.3 ./src/META-INF/beans.xml full listing • 7.4 ./src/com/bookstore/Book.java • 7.5 ./src/com/bookstore/BookRepositoryImpl.java full listing (testing only) • 7.6 ./src/com/bookstore/BookRepository.java full listing • 7.7 ./src/com/bookstore/web/BookEditorServlet.java • 7.8 ./src/com/bookstore/web/BookListServlet.java • 8 Technical debt • 9 Cookbooks and Tutorials Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 6. Where  we  leX  off  in  last  example • BookListServlet  uses  a  BookRepository  object  (DAO)  to  load  a   list  of  books   • BookListServlet  then  delegated  to  book-­‐list.jsp  to  render  the   book  lis8ng  with  JSTL  and  Unified  EL • In  this  cookbook,   • add  a  link  to  the  book  lis9ng  for  edi9ng  a  book • add  a  link  so  that  the  end  user  can  add  a  new  book  to  the  lis9ng • Create  backend  Servlets  to  handle  new  links  on  book  lis9ng Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 7. Model  2  MVC Model View Controller •BookListingServlet •Book •book-form.jsp •BookEditorServlet •BookRepositoryImpl •book-list.jsp •BookRepository Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 8. Add  a  new  link  to  book-­‐lis8ng.jsp • Add  link  to  edit  opera8on • Edit  opera8on  pulls  up  form  with  details  of  Book  8tle  that  is  clicked • Uses  <a  href=”” • Uses  expression  pageContext.request.contextPath/book  to  address  new  Edit  Servlet • Servlet  created  later,  id  parameter  implies  edit  opertaion • EL  expression  pageContext.request.contextPath  refers  to  the  URI,  web  app  (war  file)  is   mapped  to  in  Servlet  container Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 9. Edit  Link  on  Title Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 10. What  gets  rendered • The  following  links  with  URI  (/bookstore)  of  webapp  get  rendered  when  book-­‐ lis8ng.jsp  loads Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 11. Adding  a  “add  a  book”  link  to  book  lis8ng • Now  that  links  are  going  to  URI  /book,   • You  need  a  Servlet  that  handles  links • For  add  opera9on  and  edit  opera9on • New  BookEditorServlet  will  handle  both  add  and  edit  book  func8ons Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 12. Add  Link  Above  Table Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 13. BookEditorServlet • @WebServlet("/book")  maps  BookEditorServlet  to  the  URI  / book • Common  to  load  a  form  from  a  doGet  method,  and  to  handle   the  form  submission  via  doPost • Follows  REST  and  HTTP  principles  GET  opera8ons  reads  data,   • later  POST  data  modifies  data • doGet  method  uses  id  being  empty  or  not  to   • determine  if  this  is  a  load  "Add  Book  Form"  or   • load  "Update  Book  Form"  opera9on Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 14. BookEditorServlet Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 15. BookEditorServlet.doGet  loads  edit/add  form Add Link Edit Link doGet is load form operation book-form.jsp Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 16. Model  2  and  BookEditorServlet.doGet • In  Model  2,  Servlets  (controllers/ac8ons)  prepares  model  data  for  the  view • This  includes  date  formagng Notice “book” is mapped into request scope “book” will get used from book-form.jsp Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 17. Model  2  and  BookEditorServlet.doGet  (cont) • To  render  the  HTML  form,  the  servlet  delegates  to  book-­‐form.jsp book-form.jsp Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 18. book-­‐form.jsp  (1  of  3) • book-­‐form.jsp  renders  form  to  edit  book   • If  book.id  present  then  edit  opera8on,  otherwise  add  opera8on • JSTL  c:choose,  c:otherwise  to  display  correct  9tle  based  on  Update  (Edit)  or  Add   opera9on Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 19. book-­‐form.jsp  (2  of  3) • Uses  Unified  EL  to  render  values  and  then  just  plain  HTML  for  form  fields Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 20. book-­‐form.jsp  (3  of  3) • hidden  id  property  is  rendered  if  edit  (Update)  opera8on • Cancel  buNon  takes  them  back  to  lis8ng  (/book/  is  lis8ng). • Submit  buNon  POST  form  to  BookEditorServlet.doPost  (defined  next) Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 21. BookEditorServlet.doPost() • if  id  request  parameter  is  null  then  BookEditorServlet.doPost   calls  bookRepo.addBook,   • otherwise  it  calls  bookRepo.updateBook •  Then,  doPost  redirects  to  /book/ • redirect  means  an  extra  hit  to  the  server,   • basically  telling  browser  to  load  another  link • Not  forward  like  before  because  of  bookmarking • Remember  URL  /book/  (ending  in  slash)  represents  a  collec9on  of   books,  while  /book  (no  slash)  represents  a  single  book   • If  doPost  did  a  forward,  then  browser  would  show  wrong  link  for   lis9ng • Use  sendRedirect  instead  of  a  forward  for  bookmarking Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 22. BookEditorServlet.doPost() Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 23. BookEditorServlet.doPost book-form.jsp BookListServlet Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 24. Review  of  CRUD  lis8ng • Book  Form • Servlet  that  loads  Book  (doGet)  form   • ./WebContent/WEB-­‐INF/pages/book-­‐form.jsp                   and  handles  Book  form  submissions   (doPost). • Book  Lis8ng • ./WebContent/WEB-­‐INF/pages/book-­‐list.jsp                           ./src/com/bookstore/web/ BookEditorServlet.java             • Needed  for  Java  EE  dependency  injec8on  (CDI) • ./src/META-­‐INF/beans.xml                                                                                 • Servlet  that  looks  up  a  list  of  books  and   displays  the  lis8ng • Domain/model  object ./src/com/bookstore/web/ • ./src/com/bookstore/Book.java                                                                 BookListServlet.java                   • Repository  implementa8on  using  Java  collec8ons   (just  for  tes8ng) • ./src/com/bookstore/BookRepositoryImpl.java                 • Interface  to  Book  Repository  so  we  can  swap  it  out   with  JDBC,  JPA,  JCache  and  MongoDB  version  later • ./src/com/bookstore/BookRepository.java               Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server
  • 25. Open%Source,%Reliable%and%Lightweight% Java%EE%Applica;on%Server% RESIN PRO Web Profile Health System Cloud Support
  • 26. More  Info • Caucho  Technology  |  Home  Page • Resin  |  Applica8on  Server • Resin  |  Java  EE  Web  Profile  Applica8on  Server • Resin  -­‐  Cloud  Support  |  3G  -­‐  Java  Clustering • Resin  |  Java  CDI  |  Dependency  Injec8on  /  IoC • Resin  -­‐  Health  System  |  Java  Monitoring  and  Server  Monitoring • Download  Resin  |  Applica8on  Server • Watch  Resin  |  Applica8on  Server  Featured  Video Caucho  Home    |    Contact  Us    |    Caucho  Blog    |    Wiki    |  Applica8on  Server