Analyzing Struts and Spring  by Developing an Online Bookstore  Web Application Vidhya SampathKumaran Beulah David Graduat...
Overview <ul><li>Why Struts and Spring? </li></ul><ul><li>Overview of Struts, Spring and their architecture </li></ul><ul>...
Why Struts & Spring? <ul><li>Strict Enforcement of MVC Pattern in Struts and Spring </li></ul><ul><li>Separation of Concer...
Struts Overview <ul><li>Struts is a Single tier Web Framework </li></ul><ul><li>Development framework for Java servlet app...
Spring Overview <ul><li>Spring is a lightweight application framework </li></ul><ul><li>Spring provides an integrated fram...
Struts Architecture <ul><li>Controller manages common system Controller services, e.g. security services, data validation ...
Spring Architecture <ul><li>Loosely coupled design enabling easy </li></ul><ul><li>integration with O/R mapping frameworks...
Spring’s Dependency Injection <ul><li>Form of IoC that removes explicit dependence on container APIs </li></ul><ul><li>Fla...
Dependency Injection  contd <ul><li><bean id=&quot;searchBean&quot; class=&quot;spring.SearchController&quot;> </li></ul><...
Implementation differences Configuration Files <ul><li>Extract the flow logic into Metadata form in configuration file </l...
Implementation Differences Struts Action Vs Spring Controller <ul><li>All Struts action classes extends “Action” Class res...
Implementation Differences ActionForms vs POJO’s <ul><li>Struts:  forms must be backed by an ActionForm (ValidatorForm for...
Implementation Differences Validation <ul><li>Both frameworks can use Commons Validator using validation.xml, validation-r...
Validation  contd <ul><li>Spring: programmatic validation in a Validator class which implements org.springframework.valida...
Implementation Differences Taglibs <ul><li>Struts  – Rich JSP taglibs:  JSP Custom Tag Libraries: </li></ul><ul><ul><li>Be...
Internationalization <ul><li>Internationalization is the process of designing an application so that it can be adapted to ...
Interceptor in Spring <ul><li>Interceptor like filters can intercept a request and apply specific functionality to the req...
BookStore Web Application Web Flow Diagram
Demo
Performance Analysis <ul><li>Conducted simple performance & scalability tests on our web application to compare Struts and...
Jmeter: Struts Load performance Results <ul><ul><li>Struts Web App:  20 users </li></ul></ul><ul><ul><li>Avg Response Time...
Jmeter: Spring Load Performance Results <ul><ul><li>SpringWeb App:  20 users </li></ul></ul><ul><ul><li>Avg Response Time ...
Load Performance Comparison   <ul><li>Struts Web App. handles 15-20 users with tolerable Resp. time </li></ul><ul><li>Spri...
CPU Performance Comparison CPU Characteristics
Memory Performance Comparison Memory Characteristics
Performance test Inference <ul><li>Total Avg Resp. Time : Spring Web App better compared to that of Struts </li></ul><ul><...
Ease of Use: Spring & Struts Web App <ul><li>Code size </li></ul><ul><ul><li>Struts (209KB) > Spring (186KB) </li></ul></u...
Key Features of Struts <ul><li>Powerful Validation  </li></ul><ul><li>Rich Taglibs </li></ul><ul><li>Java tools and integr...
Key Features of Spring <ul><li>Dependency Injection </li></ul><ul><li>Spring can be integrated with many languages like (c...
Conclusion <ul><li>Spring Advantages over Struts:  </li></ul><ul><li>Dependency Injection: </li></ul><ul><ul><li>Lesser In...
References <ul><li>http://www.springframework.org/docs/reference/mvc.html </li></ul><ul><li>http://struts.apache.org/ </li...
Questions <ul><li>? </li></ul>
Thank You!
Appendix
CPU call tree: Struts
CPU Call tree: Spring
Memory Allocation Call tree: Struts
Memory Allocation Call Tree- Spring
Upcoming SlideShare
Loading in …5
×

Book Store Webapplication with Struts & Spring

5,133 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,133
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
183
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Book Store Webapplication with Struts & Spring

  1. 1. Analyzing Struts and Spring by Developing an Online Bookstore Web Application Vidhya SampathKumaran Beulah David Graduate Students CST425 Group Project, Fall 2005
  2. 2. Overview <ul><li>Why Struts and Spring? </li></ul><ul><li>Overview of Struts, Spring and their architecture </li></ul><ul><li>Dependency injection in Spring </li></ul><ul><li>Implementation Differences between Struts & Spring </li></ul><ul><li>Demo of our application </li></ul><ul><li>Performance analysis of Struts & Spring bookstore web application </li></ul><ul><li>Keyfeatures of Struts and Spring </li></ul><ul><li>Conclusion </li></ul>
  3. 3. Why Struts & Spring? <ul><li>Strict Enforcement of MVC Pattern in Struts and Spring </li></ul><ul><li>Separation of Concerns-View separated from Controller </li></ul><ul><li>Effective use of Tag libraries </li></ul><ul><li>Internationalization </li></ul><ul><li>Better Form Validation </li></ul><ul><li>Easier to modify the applications using config file </li></ul>
  4. 4. Struts Overview <ul><li>Struts is a Single tier Web Framework </li></ul><ul><li>Development framework for Java servlet applications based upon (MVC) design paradigm – Model 2 approach </li></ul>
  5. 5. Spring Overview <ul><li>Spring is a lightweight application framework </li></ul><ul><li>Spring provides an integrated framework for all tiers of the application </li></ul>
  6. 6. Struts Architecture <ul><li>Controller manages common system Controller services, e.g. security services, data validation </li></ul><ul><li>Declarative navigation maps logical flow to implemented pages </li></ul><ul><li>‘ forward’ options are specified in struts-config.xml, rather than in Java code code </li></ul><ul><li>Substantial tag library for JSP pages makes framework easy to use </li></ul><ul><li>ActionForm, makes it easy to read, validate and write data to JSP pages </li></ul>
  7. 7. Spring Architecture <ul><li>Loosely coupled design enabling easy </li></ul><ul><li>integration with O/R mapping frameworks like Hibernate, TopLink , EJB3 </li></ul><ul><li>View-agnostic - Easy integration with any view technology like Velocity, Tiles, XSLT </li></ul><ul><li>Spring Framework also provides transaction management, data access abstraction and AOP support </li></ul><ul><li>Inversion of Control and Dependency Injection: Reducing proliferation of singleton objects </li></ul>
  8. 8. Spring’s Dependency Injection <ul><li>Form of IoC that removes explicit dependence on container APIs </li></ul><ul><li>Flavors: Setter, Constructor, Method </li></ul><ul><li>Loose coupling </li></ul><ul><li>Code focuses on relevant business logic </li></ul><ul><li>Dependencies are explicit </li></ul><ul><li>Reduction of code </li></ul>
  9. 9. Dependency Injection contd <ul><li><bean id=&quot;searchBean&quot; class=&quot;spring.SearchController&quot;> </li></ul><ul><li><property name=&quot;sessionForm&quot;><value>true</value></property> </li></ul><ul><li><property name=&quot;commandName&quot;><value>search</value></property> </li></ul><ul><li><property name=&quot;commandClass&quot;><value>spring.pojo.Search</value></property> </li></ul><ul><li><property name=&quot;validator&quot;><ref bean=&quot;searchValidator&quot;/></property> </li></ul><ul><li><property name=&quot;formView&quot;><value>search</value></property> </li></ul><ul><li><property name=&quot;successView&quot;><value>bookdetails.htm</value></property> </li></ul><ul><li><property name=&quot;purchaseSystemUtil&quot;> </li></ul><ul><li><ref bean=&quot;purchaseSystem&quot;/> </li></ul><ul><li></property> </li></ul><ul><li></bean> </li></ul><ul><li><bean id=&quot;purchaseSystem&quot; class=&quot;spring.PurchaseSystemUtil&quot;> </li></ul><ul><li><property name=&quot;sessionManager&quot;> </li></ul><ul><li><ref bean=&quot;sessionMgr&quot;/> </li></ul><ul><li></property> </li></ul><ul><li></bean> </li></ul><ul><li><bean id=&quot;sessionMgr&quot; class=&quot;spring.SessionManager&quot;> </li></ul><ul><li></bean> </li></ul>
  10. 10. Implementation differences Configuration Files <ul><li>Extract the flow logic into Metadata form in configuration file </li></ul><ul><li>Struts Actions configured as “mappings” in strutsconfig.xml: </li></ul><ul><li><action name=&quot;SearchForm&quot; path=&quot;/search&quot; scope=&quot;request&quot; type=&quot;bookapplication.actions.SearchAction&quot; input=&quot;/search.jsp&quot;> </li></ul><ul><li><forward contextRelative=&quot;true&quot; name=&quot;success&quot; path=&quot;/bookDetails.jsp&quot;/> </li></ul><ul><li><forward contextRelative=&quot;true&quot; name=&quot;error&quot; path=&quot;/search.jsp&quot;/> </li></ul><ul><li></action> </li></ul><ul><li>Spring Controllers configured as “beans” in actionservlet.xml: </li></ul><ul><li><bean id=&quot;searchBean&quot; class=&quot;spring.SearchController&quot;> </li></ul><ul><li><property name=&quot;sessionForm&quot;><value>true</value></property> </li></ul><ul><li><property name=&quot;commandName&quot;><value>search</value></property> </li></ul><ul><li><property name=&quot;commandClass&quot;><value>spring.pojo.Search</value></property> </li></ul><ul><li><property name=&quot;validator&quot;><ref bean=&quot;searchValidator&quot;/></property> </li></ul><ul><li><property name=&quot;formView&quot;><value>search</value></property> </li></ul><ul><li><property name=&quot;successView&quot;><value>bookdetails.htm</value></property> </li></ul><ul><li><property name=&quot;purchaseSystemUtil&quot;> </li></ul><ul><li><ref bean=&quot;purchaseSystem&quot;/> </li></ul><ul><li></property> </li></ul><ul><li></bean> </li></ul>
  11. 11. Implementation Differences Struts Action Vs Spring Controller <ul><li>All Struts action classes extends “Action” Class restricting further inheritance. </li></ul><ul><li>All Spring controller classes implements “Controller” giving an advantage. </li></ul><ul><li>Struts objects are pointers into presentation resources (Actions, JSPs, Tiles, HTML files, etc.). </li></ul><ul><li>session.setAttribute(“BookCollection”,BookHelperBean); </li></ul><ul><li>forward = mapping.findForward(&quot;success&quot;); </li></ul><ul><li> return (forward); </li></ul><ul><li>Spring returns implementation of the ModelAndView interface </li></ul><ul><li>Model components contain the business object to be displayed via the View component </li></ul><ul><li>return new ModelAndView(new RedirectView(getSuccessView())); </li></ul><ul><li>Map myModel = new HashMap(); </li></ul><ul><li>myModel.put(&quot;now&quot;, now); </li></ul><ul><li>myModel.put(&quot;products&quot;, getProductManager().getProducts()); </li></ul><ul><li>return new ModelAndView(&quot;hello&quot;, &quot;model&quot;, myModel); </li></ul>
  12. 12. Implementation Differences ActionForms vs POJO’s <ul><li>Struts: forms must be backed by an ActionForm (ValidatorForm for validation) - which is a Java representation of the HTML form </li></ul><ul><li>Contains all form properties in String form </li></ul><ul><li>Use BeanUtils.copyProperties to convert from </li></ul><ul><li>ActionForm to POJO </li></ul><ul><li>Spring : forms use POJOs as “command objects” which are independent and reusable </li></ul>
  13. 13. Implementation Differences Validation <ul><li>Both frameworks can use Commons Validator using validation.xml, validation-rules.xml </li></ul><ul><li>Reuse ResourceBundleMessage – Application Resources </li></ul><ul><li>Struts: programmatic validation in your ValidatorForm’s validate() method </li></ul><ul><li>public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) </li></ul><ul><li>{ </li></ul><ul><li>ActionErrors errors = new ActionErrors(); </li></ul><ul><li>if((shipDate ==null) || (shipDate.length() ==0)) </li></ul><ul><li>{ </li></ul><ul><li>errors.add(&quot;shipDate&quot;,ActionError(&quot;errors.required&quot;, &quot;ShipDate &quot;)); </li></ul><ul><li> } </li></ul><ul><li> return errors </li></ul><ul><li>} </li></ul>
  14. 14. Validation contd <ul><li>Spring: programmatic validation in a Validator class which implements org.springframework.validation.Validator </li></ul><ul><ul><li>public void validate(Object obj, Errors errors) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>Search search = (Search) obj; </li></ul></ul><ul><ul><li>if (search == null) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>errors.rejectValue(&quot;search&quot;, &quot;error.not-specified&quot;, null, &quot;Value required.&quot;); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  15. 15. Implementation Differences Taglibs <ul><li>Struts – Rich JSP taglibs: JSP Custom Tag Libraries: </li></ul><ul><ul><li>Bean – General bean manipulation </li></ul></ul><ul><ul><li>Html – Render HTML markup </li></ul></ul><ul><ul><li>Logic – Conditionals and iteration </li></ul></ul><ul><ul><li>Nested – Versions of standard tags for navigating </li></ul></ul><ul><ul><li>bean hierarchies </li></ul></ul><ul><ul><li>Tiles – Layout management </li></ul></ul><ul><li>Spring – custom tags: </li></ul><ul><li>Enables binding of Command objects into web forms ex: spring:bind, spring:hasBindErrors etc </li></ul><ul><li>Also supports JSTL taglibs , velocity for other tasks to reduce html code generation </li></ul>
  16. 16. Internationalization <ul><li>Internationalization is the process of designing an application so that it can be adapted to various languages and regions. </li></ul><ul><li>Struts </li></ul><ul><li>- built in Internationalization </li></ul><ul><li>- Uses struts-html tag library </li></ul><ul><ul><li><bean:message/>tag and <html:html locale=“true”> in jsp </li></ul></ul><ul><li>In struts-config.xml </li></ul><ul><li><form-bean name=&quot;localeForm&quot; </li></ul><ul><li> type=&quot;org.apache.struts.action.DynaActionForm&quot;> </li></ul><ul><li> <form-property name=&quot;language&quot; type=&quot;java.lang.String&quot;/> </li></ul><ul><li> <form-property name=&quot;country&quot; type=&quot;java.lang.String&quot;/> </li></ul><ul><li></form-bean> </li></ul><ul><li>- Can also use JSTl tag library </li></ul><ul><li>Spring </li></ul><ul><li> - Uses JSTl tag library and <fmt:message/> tag in jsp </li></ul><ul><li>In springapp-servlet.xml </li></ul><ul><li><bean id=&quot;localeChangeInterceptor&quot; </li></ul><ul><li>class=&quot;org.springframework.web.servlet.i18n.LocaleChangeInterceptor&quot;> </li></ul><ul><li><property name=&quot;paramName&quot;><value>siteLanguage</value></property> </li></ul><ul><li></bean> </li></ul><ul><li><bean id=&quot;localeResolver&quot; </li></ul><ul><li>class=&quot;org.springframework.web.servlet.i18n.SessionLocaleResolver&quot;/> </li></ul>
  17. 17. Interceptor in Spring <ul><li>Interceptor like filters can intercept a request and apply specific functionality to the request before or after the execution of the handler. Shown below is the declaration of the interceptor in the servlet-config.xml: </li></ul><ul><li><bean id=&quot;handlerMapping&quot; class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;> </li></ul><ul><li><property name=&quot;interceptors&quot;> </li></ul><ul><li><list> </li></ul><ul><li><ref bean=&quot;AuthInterceptor&quot;/> </li></ul><ul><li></list> </li></ul><ul><li></property> </li></ul><ul><li><property name=&quot;mappings&quot;> </li></ul><ul><li><props> </li></ul><ul><li><prop key=&quot;/protected/orderDetails.htm&quot;>orderDetails</prop> </li></ul><ul><li><prop key=&quot;/protected/orderHome.htm&quot;>orderhome</prop> </li></ul><ul><li></props> </li></ul><ul><li></property> </li></ul><ul><li></bean> </li></ul>
  18. 18. BookStore Web Application Web Flow Diagram
  19. 19. Demo
  20. 20. Performance Analysis <ul><li>Conducted simple performance & scalability tests on our web application to compare Struts and Spring </li></ul><ul><ul><li>Load test: Used Jmeter to record avg response time and throughput for 5, 10, 15, and 20 users </li></ul></ul><ul><ul><li>CPU & Memory Performance Test: Used Jprofiler </li></ul></ul><ul><li>Test Case: </li></ul><ul><ul><li>User performs: </li></ul></ul><ul><li>Machine Characteristics </li></ul><ul><ul><li>Memory: 327 MB </li></ul></ul><ul><ul><li>Processor: Intel Pentium IV </li></ul></ul>Add to cart Check out Log in Search Create new order List order
  21. 21. Jmeter: Struts Load performance Results <ul><ul><li>Struts Web App: 20 users </li></ul></ul><ul><ul><li>Avg Response Time = 21 sec </li></ul></ul>
  22. 22. Jmeter: Spring Load Performance Results <ul><ul><li>SpringWeb App: 20 users </li></ul></ul><ul><ul><li>Avg Response Time = 2.5 sec </li></ul></ul>
  23. 23. Load Performance Comparison <ul><li>Struts Web App. handles 15-20 users with tolerable Resp. time </li></ul><ul><li>Spring Web App. handles 30 users with less Resp time </li></ul>
  24. 24. CPU Performance Comparison CPU Characteristics
  25. 25. Memory Performance Comparison Memory Characteristics
  26. 26. Performance test Inference <ul><li>Total Avg Resp. Time : Spring Web App better compared to that of Struts </li></ul><ul><li>Load Performance : Spring Web App. better load performance (upto 30 users with avg response time less than 7sec) </li></ul><ul><li>Spring WebApp is likely to be better because: </li></ul><ul><ul><li>Creation of Singleton objects in Spring Web App </li></ul></ul><ul><ul><li>Reduced Instantiation of Objects </li></ul></ul><ul><ul><ul><li>Dependency Injection in Spring as opposed to creation of new object each time in Struts </li></ul></ul></ul><ul><ul><li>Singleton was not created in Struts Web. App. </li></ul></ul><ul><ul><li>Other Aspects (Code Optimization, network latency) </li></ul></ul>
  27. 27. Ease of Use: Spring & Struts Web App <ul><li>Code size </li></ul><ul><ul><li>Struts (209KB) > Spring (186KB) </li></ul></ul><ul><li>Learning Curve </li></ul><ul><ul><li>Struts easier because of availability of documentation, knowledge base </li></ul></ul><ul><li>Coding </li></ul><ul><ul><li>Spring easier because of Spring-config file </li></ul></ul>
  28. 28. Key Features of Struts <ul><li>Powerful Validation </li></ul><ul><li>Rich Taglibs </li></ul><ul><li>Java tools and integration with IDE’s </li></ul><ul><li>Experienced and technical support </li></ul>
  29. 29. Key Features of Spring <ul><li>Dependency Injection </li></ul><ul><li>Spring can be integrated with many languages like (c#,) other than java </li></ul><ul><li>Moves exception handling out of code into the framework </li></ul><ul><li>Easier code change </li></ul><ul><li>Easier to unit test </li></ul><ul><li>Easier to migrate from Spring to other technologies </li></ul>
  30. 30. Conclusion <ul><li>Spring Advantages over Struts: </li></ul><ul><li>Dependency Injection: </li></ul><ul><ul><li>Lesser Instantiation of Objects </li></ul></ul><ul><ul><li>Smaller Code Size & Greater Reusability of Code </li></ul></ul><ul><li>Integration with all Tiers: </li></ul><ul><ul><li>Easier to Plug with other Frameworks & Technology </li></ul></ul><ul><li>Easier to Modify Applications </li></ul><ul><li>Better Avg. Response Time </li></ul><ul><li>Better Load Performance </li></ul><ul><li>Spring better Framework than Struts for our Web App. </li></ul>
  31. 31. References <ul><li>http://www.springframework.org/docs/reference/mvc.html </li></ul><ul><li>http://struts.apache.org/ </li></ul><ul><li>http://www.theserverside.com/articles/article.tss?l=SpringFramework </li></ul><ul><li>http://javaboutique.internet.com/tutorials/Struts/ </li></ul><ul><li>http://javaboutique.internet.com/tutorials/spring_frame/ </li></ul><ul><li>http://jakarta.apache.org/jmeter/ </li></ul><ul><li>http://www.ej-echnologies.com/products/jprofiler/overview.html </li></ul>
  32. 32. Questions <ul><li>? </li></ul>
  33. 33. Thank You!
  34. 34. Appendix
  35. 35. CPU call tree: Struts
  36. 36. CPU Call tree: Spring
  37. 37. Memory Allocation Call tree: Struts
  38. 38. Memory Allocation Call Tree- Spring

×