Your SlideShare is downloading. ×
0
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Book Store Webapplication with  Struts & Spring
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Book Store Webapplication with Struts & Spring

4,563

Published on

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

No Downloads
Views
Total Views
4,563
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
173
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Analyzing Struts and Spring by Developing an Online Bookstore Web Application Vidhya SampathKumaran Beulah David Graduate Students CST425 Group Project, Fall 2005
  • 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 &amp; Spring </li></ul><ul><li>Demo of our application </li></ul><ul><li>Performance analysis of Struts &amp; Spring bookstore web application </li></ul><ul><li>Keyfeatures of Struts and Spring </li></ul><ul><li>Conclusion </li></ul>
  • 3. Why Struts &amp; 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. 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. 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. 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. 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. 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. Dependency Injection contd <ul><li>&lt;bean id=&amp;quot;searchBean&amp;quot; class=&amp;quot;spring.SearchController&amp;quot;&gt; </li></ul><ul><li>&lt;property name=&amp;quot;sessionForm&amp;quot;&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;commandName&amp;quot;&gt;&lt;value&gt;search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;commandClass&amp;quot;&gt;&lt;value&gt;spring.pojo.Search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;validator&amp;quot;&gt;&lt;ref bean=&amp;quot;searchValidator&amp;quot;/&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;formView&amp;quot;&gt;&lt;value&gt;search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;successView&amp;quot;&gt;&lt;value&gt;bookdetails.htm&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;purchaseSystemUtil&amp;quot;&gt; </li></ul><ul><li>&lt;ref bean=&amp;quot;purchaseSystem&amp;quot;/&gt; </li></ul><ul><li>&lt;/property&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul><ul><li>&lt;bean id=&amp;quot;purchaseSystem&amp;quot; class=&amp;quot;spring.PurchaseSystemUtil&amp;quot;&gt; </li></ul><ul><li>&lt;property name=&amp;quot;sessionManager&amp;quot;&gt; </li></ul><ul><li>&lt;ref bean=&amp;quot;sessionMgr&amp;quot;/&gt; </li></ul><ul><li>&lt;/property&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul><ul><li>&lt;bean id=&amp;quot;sessionMgr&amp;quot; class=&amp;quot;spring.SessionManager&amp;quot;&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul>
  • 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>&lt;action name=&amp;quot;SearchForm&amp;quot; path=&amp;quot;/search&amp;quot; scope=&amp;quot;request&amp;quot; type=&amp;quot;bookapplication.actions.SearchAction&amp;quot; input=&amp;quot;/search.jsp&amp;quot;&gt; </li></ul><ul><li>&lt;forward contextRelative=&amp;quot;true&amp;quot; name=&amp;quot;success&amp;quot; path=&amp;quot;/bookDetails.jsp&amp;quot;/&gt; </li></ul><ul><li>&lt;forward contextRelative=&amp;quot;true&amp;quot; name=&amp;quot;error&amp;quot; path=&amp;quot;/search.jsp&amp;quot;/&gt; </li></ul><ul><li>&lt;/action&gt; </li></ul><ul><li>Spring Controllers configured as “beans” in actionservlet.xml: </li></ul><ul><li>&lt;bean id=&amp;quot;searchBean&amp;quot; class=&amp;quot;spring.SearchController&amp;quot;&gt; </li></ul><ul><li>&lt;property name=&amp;quot;sessionForm&amp;quot;&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;commandName&amp;quot;&gt;&lt;value&gt;search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;commandClass&amp;quot;&gt;&lt;value&gt;spring.pojo.Search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;validator&amp;quot;&gt;&lt;ref bean=&amp;quot;searchValidator&amp;quot;/&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;formView&amp;quot;&gt;&lt;value&gt;search&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;successView&amp;quot;&gt;&lt;value&gt;bookdetails.htm&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;purchaseSystemUtil&amp;quot;&gt; </li></ul><ul><li>&lt;ref bean=&amp;quot;purchaseSystem&amp;quot;/&gt; </li></ul><ul><li>&lt;/property&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul>
  • 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(&amp;quot;success&amp;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(&amp;quot;now&amp;quot;, now); </li></ul><ul><li>myModel.put(&amp;quot;products&amp;quot;, getProductManager().getProducts()); </li></ul><ul><li>return new ModelAndView(&amp;quot;hello&amp;quot;, &amp;quot;model&amp;quot;, myModel); </li></ul>
  • 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. 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(&amp;quot;shipDate&amp;quot;,ActionError(&amp;quot;errors.required&amp;quot;, &amp;quot;ShipDate &amp;quot;)); </li></ul><ul><li> } </li></ul><ul><li> return errors </li></ul><ul><li>} </li></ul>
  • 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(&amp;quot;search&amp;quot;, &amp;quot;error.not-specified&amp;quot;, null, &amp;quot;Value required.&amp;quot;); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  • 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. 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>&lt;bean:message/&gt;tag and &lt;html:html locale=“true”&gt; in jsp </li></ul></ul><ul><li>In struts-config.xml </li></ul><ul><li>&lt;form-bean name=&amp;quot;localeForm&amp;quot; </li></ul><ul><li> type=&amp;quot;org.apache.struts.action.DynaActionForm&amp;quot;&gt; </li></ul><ul><li> &lt;form-property name=&amp;quot;language&amp;quot; type=&amp;quot;java.lang.String&amp;quot;/&gt; </li></ul><ul><li> &lt;form-property name=&amp;quot;country&amp;quot; type=&amp;quot;java.lang.String&amp;quot;/&gt; </li></ul><ul><li>&lt;/form-bean&gt; </li></ul><ul><li>- Can also use JSTl tag library </li></ul><ul><li>Spring </li></ul><ul><li> - Uses JSTl tag library and &lt;fmt:message/&gt; tag in jsp </li></ul><ul><li>In springapp-servlet.xml </li></ul><ul><li>&lt;bean id=&amp;quot;localeChangeInterceptor&amp;quot; </li></ul><ul><li>class=&amp;quot;org.springframework.web.servlet.i18n.LocaleChangeInterceptor&amp;quot;&gt; </li></ul><ul><li>&lt;property name=&amp;quot;paramName&amp;quot;&gt;&lt;value&gt;siteLanguage&lt;/value&gt;&lt;/property&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul><ul><li>&lt;bean id=&amp;quot;localeResolver&amp;quot; </li></ul><ul><li>class=&amp;quot;org.springframework.web.servlet.i18n.SessionLocaleResolver&amp;quot;/&gt; </li></ul>
  • 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>&lt;bean id=&amp;quot;handlerMapping&amp;quot; class=&amp;quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&amp;quot;&gt; </li></ul><ul><li>&lt;property name=&amp;quot;interceptors&amp;quot;&gt; </li></ul><ul><li>&lt;list&gt; </li></ul><ul><li>&lt;ref bean=&amp;quot;AuthInterceptor&amp;quot;/&gt; </li></ul><ul><li>&lt;/list&gt; </li></ul><ul><li>&lt;/property&gt; </li></ul><ul><li>&lt;property name=&amp;quot;mappings&amp;quot;&gt; </li></ul><ul><li>&lt;props&gt; </li></ul><ul><li>&lt;prop key=&amp;quot;/protected/orderDetails.htm&amp;quot;&gt;orderDetails&lt;/prop&gt; </li></ul><ul><li>&lt;prop key=&amp;quot;/protected/orderHome.htm&amp;quot;&gt;orderhome&lt;/prop&gt; </li></ul><ul><li>&lt;/props&gt; </li></ul><ul><li>&lt;/property&gt; </li></ul><ul><li>&lt;/bean&gt; </li></ul>
  • 18. BookStore Web Application Web Flow Diagram
  • 19. Demo
  • 20. Performance Analysis <ul><li>Conducted simple performance &amp; 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 &amp; 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. 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. 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. 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. CPU Performance Comparison CPU Characteristics
  • 25. Memory Performance Comparison Memory Characteristics
  • 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. Ease of Use: Spring &amp; Struts Web App <ul><li>Code size </li></ul><ul><ul><li>Struts (209KB) &gt; 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. 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. 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. 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 &amp; Greater Reusability of Code </li></ul></ul><ul><li>Integration with all Tiers: </li></ul><ul><ul><li>Easier to Plug with other Frameworks &amp; 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. 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. Questions <ul><li>? </li></ul>
  • 33. Thank You!
  • 34. Appendix
  • 35. CPU call tree: Struts
  • 36. CPU Call tree: Spring
  • 37. Memory Allocation Call tree: Struts
  • 38. Memory Allocation Call Tree- Spring

×