Ajax on Struts 2
About Myself Chad Davis Blackdog Software, Inc. J2EE Consulting Corporate Training Struts 2 in Action Open Source Enthusiast  Debian Devotee
Road Map  Something for everyone Struts 2 introduction Ajax introduction Walk through a code sample Questions at any time
Struts 2 Web application framework Java Servlets Second generation Software engineering
Classic versus Ajax Classic Web Applications Ajax Web Applications
Classic Web Applications URL: /manningSampleApp/chapterEight/ClassicRetrieveUser.action Data: username=mary
How it works: classic style Browser makes request Http URL Data Server Processes data Sends HTML page response Browser receives, renders HTML
< html > < head > < link  rel = &quot;stylesheet&quot;  type = &quot;text/css&quot;  href = &quot;css/classicUserBrowser.css&quot;  /> </ head > < body > < h2 > Artist Browser Control </ h2 > < form  id = &quot;ClassicRetrieveUser&quot;  name = &quot;ClassicRetrieveUser&quot;  onsubmit = &quot;return true;&quot; action = &quot;/manningSampleApp/chapterEight/ClassicRetrieveUser.action&quot;  method = &quot;post&quot; > < table  class = &quot;wwFormTable&quot; > < tr > < td  class = &quot;tdLabel&quot; >< label  for = &quot;ClassicRetrieveUser_username&quot;  class = &quot;label&quot; > Select an artist: </ label ></ td > < td >< select  name = &quot;username&quot;  id = &quot;ClassicRetrieveUser_username&quot; > < option  value = &quot;Jimmy&quot; > Jimmy </ option > < option  value = &quot;Charlie Joe&quot; > Charlie Joe </ option > < option  value = &quot;Mary&quot;  selected = &quot;selected&quot; > Mary </ option > < option  value = &quot;Arty&quot; > Arty </ option > </ select ></ td > </ tr > < tr > < td  colspan = &quot;2&quot; > < div  align = &quot;right&quot; >< input  type = &quot;submit&quot;  id = &quot;ClassicRetrieveUser_0&quot;  value = &quot;Submit&quot;  /></ div > </ td > </ tr > </ table > </ form > < hr /> < h2 > Artist Information </ h2 > < div  id = 'console' > < p >< span  class = &quot;browser_label&quot; > Name: </ span >  Mary Greene </ p > < p >< span  class = &quot;browser_label&quot; > PortfolioName:  </ span > Wood Cuts </ p > < p >< span  class = &quot;browser_label&quot; > PortfolioName:  </ span > Oil Paintings </ p > </ div > </ body > </ html >
Classic Problems Slow High bandwidth Redundant Page rendering
Ajax Web Applications URL: /manningSampleApp/chapterEight/ClassicRetrieveUser.action Data: username=mary
How it works: Ajax Browser uses Javascript to submit  request Http URL Data Server Processes data Sends data response ( JSON, XML, etc. ) Browser Javascript Proceses data DHTML
 
Ajax Selling Points Low bandwith No page rendering issues Supports a stronger Separation of Concerns
Observations . . . What does the server do? The page abstraction: JSP, ASP, PHP What should new frameworks do? What should new frameworks do?
Struts 2 Architecture Does all the dirty work for you Separation of Concerns !! Interceptors, Actions, Results, ValueStack
 
Daily development Actions you write them Results declare them write them if necessary Interceptors nothing! declare or write if necessary
Configuration Declare your actions Declare your results XML, Annotations
struts.xml <? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot;  ?> <! DOCTYPE  struts  PUBLIC  &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;  &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot; > < package  name = &quot;chapterEightPublic&quot;  namespace = &quot;/chapterEight&quot;  extends = &quot;struts-default&quot; > < action  name = &quot;ClassicUserBrowser&quot;  class = &quot;manning.chapterEight.UserBrowser&quot; > < result > classicUserBrowser.jsp </ result > </ action > </ package > </ struts > < struts >
Let's code: classic style What do we need to write? Interceptors? Results? An Action A JSP Page
Let's Code: Ajax Style What do we need to write? Interceptors? Results? An Action A JSP Page? Javascript Client Application
Summary Struts 2 – Second Generation Framework Struts 2 – Built on Software Engineering Principles  Struts 2 – Fast Development, Flexible Architecture Ajax – No Page Rendering Ajax – Javascript Client Ajax – Lower Bandwidth Ajax – JSON, XML

Ajax ons2

  • 1.
  • 2.
    About Myself ChadDavis Blackdog Software, Inc. J2EE Consulting Corporate Training Struts 2 in Action Open Source Enthusiast Debian Devotee
  • 3.
    Road Map Something for everyone Struts 2 introduction Ajax introduction Walk through a code sample Questions at any time
  • 4.
    Struts 2 Webapplication framework Java Servlets Second generation Software engineering
  • 5.
    Classic versus AjaxClassic Web Applications Ajax Web Applications
  • 6.
    Classic Web ApplicationsURL: /manningSampleApp/chapterEight/ClassicRetrieveUser.action Data: username=mary
  • 7.
    How it works:classic style Browser makes request Http URL Data Server Processes data Sends HTML page response Browser receives, renders HTML
  • 8.
    < html >< head > < link rel = &quot;stylesheet&quot; type = &quot;text/css&quot; href = &quot;css/classicUserBrowser.css&quot; /> </ head > < body > < h2 > Artist Browser Control </ h2 > < form id = &quot;ClassicRetrieveUser&quot; name = &quot;ClassicRetrieveUser&quot; onsubmit = &quot;return true;&quot; action = &quot;/manningSampleApp/chapterEight/ClassicRetrieveUser.action&quot; method = &quot;post&quot; > < table class = &quot;wwFormTable&quot; > < tr > < td class = &quot;tdLabel&quot; >< label for = &quot;ClassicRetrieveUser_username&quot; class = &quot;label&quot; > Select an artist: </ label ></ td > < td >< select name = &quot;username&quot; id = &quot;ClassicRetrieveUser_username&quot; > < option value = &quot;Jimmy&quot; > Jimmy </ option > < option value = &quot;Charlie Joe&quot; > Charlie Joe </ option > < option value = &quot;Mary&quot; selected = &quot;selected&quot; > Mary </ option > < option value = &quot;Arty&quot; > Arty </ option > </ select ></ td > </ tr > < tr > < td colspan = &quot;2&quot; > < div align = &quot;right&quot; >< input type = &quot;submit&quot; id = &quot;ClassicRetrieveUser_0&quot; value = &quot;Submit&quot; /></ div > </ td > </ tr > </ table > </ form > < hr /> < h2 > Artist Information </ h2 > < div id = 'console' > < p >< span class = &quot;browser_label&quot; > Name: </ span > Mary Greene </ p > < p >< span class = &quot;browser_label&quot; > PortfolioName: </ span > Wood Cuts </ p > < p >< span class = &quot;browser_label&quot; > PortfolioName: </ span > Oil Paintings </ p > </ div > </ body > </ html >
  • 9.
    Classic Problems SlowHigh bandwidth Redundant Page rendering
  • 10.
    Ajax Web ApplicationsURL: /manningSampleApp/chapterEight/ClassicRetrieveUser.action Data: username=mary
  • 11.
    How it works:Ajax Browser uses Javascript to submit request Http URL Data Server Processes data Sends data response ( JSON, XML, etc. ) Browser Javascript Proceses data DHTML
  • 12.
  • 13.
    Ajax Selling PointsLow bandwith No page rendering issues Supports a stronger Separation of Concerns
  • 14.
    Observations . .. What does the server do? The page abstraction: JSP, ASP, PHP What should new frameworks do? What should new frameworks do?
  • 15.
    Struts 2 ArchitectureDoes all the dirty work for you Separation of Concerns !! Interceptors, Actions, Results, ValueStack
  • 16.
  • 17.
    Daily development Actionsyou write them Results declare them write them if necessary Interceptors nothing! declare or write if necessary
  • 18.
    Configuration Declare youractions Declare your results XML, Annotations
  • 19.
    struts.xml <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> <! DOCTYPE struts PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot; &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot; > < package name = &quot;chapterEightPublic&quot; namespace = &quot;/chapterEight&quot; extends = &quot;struts-default&quot; > < action name = &quot;ClassicUserBrowser&quot; class = &quot;manning.chapterEight.UserBrowser&quot; > < result > classicUserBrowser.jsp </ result > </ action > </ package > </ struts > < struts >
  • 20.
    Let's code: classicstyle What do we need to write? Interceptors? Results? An Action A JSP Page
  • 21.
    Let's Code: AjaxStyle What do we need to write? Interceptors? Results? An Action A JSP Page? Javascript Client Application
  • 22.
    Summary Struts 2– Second Generation Framework Struts 2 – Built on Software Engineering Principles Struts 2 – Fast Development, Flexible Architecture Ajax – No Page Rendering Ajax – Javascript Client Ajax – Lower Bandwidth Ajax – JSON, XML

Editor's Notes

  • #9 Plus images, css, etc. This is a very small page.
  • #10 show amazon page refresh
  • #12 XMLHttpRequest