Your SlideShare is downloading. ×
0
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
Struts framework
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

Struts framework

621

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
621
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
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. Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  • 2. STRUTS FRAMEWORKSubhin P V111subru@gmail.comwww.facebook.com/subhinvelayudhantwitter.com/111subruin.linkedin.com/in/Subhin P V+91-8129076036
  • 3. Apache Struts• Struts Frame work is the implementation ofModel-View-Controller (MVC) design patternfor the JSP.• Struts is maintained as a part of ApacheJakarta project• Struts is open source.
  • 4. What is Model-View-Controller (MVC)Architecture?• Model-View-Controller architecture is allabout dividing application components intothree different categories Model, View andthe Controller.• Components of the MVC architecture hasunique responsibility and each component isindependent of the other component.• Changes in one component will have no orless impact on other component.
  • 5. MVC ARCHITECTURE
  • 6. Struts Architecture• Struts is an open source framework used fordeveloping J2EE web applications using ModelView Controller (MVC) design pattern.• It uses and extends the Java Servlet API toencourage developers to adopt an MVCarchitecture.
  • 7. ComponentsStruts 2 Core components are Action handler, ResultHandler and Custom Tags.Action handlerAction handler interacts with other layers.Result HandlerResult handler actually dispatches the response to view.Custom TagsCustom Tags are used render the dynamic content.
  • 8. Components• InterceptorsThe Interceptors are used to specify the"request-processing lifecycle" for an action.Interceptors are configured to apply thecommon functionalities like workflow,validation etc.. to the request. Interceptorscode is executed before and after an Action isinvoked
  • 9. How Struts Works• In struts JavaServerPages (JSP) are used todesign the dynamic web pages.• In struts, servlets helps to route request whichhas been made by the web browsers to theappropriate ServerPage.• The use of servlet as a router helps to makethe web applications easier to design, create,and maintain.
  • 10. STRUTS ARCHITECTURE
  • 11. Process flowUser Sends request.FilterDispatcher determines the appropriateaction.Interceptors are applied.Execution of Action.Output rendering.Return of Request(reverse order).Display the result to user.
  • 12. Things to download before you startstruts• Requirements (Downloads)– JDK ver. 1.5 and above.– Tomcat 5X and above(Tomcat ver.6 is better)– Eclipse ver. 3 and above.– Apache struts2 jar files needed• common-logging-1.0.4.jar• freemarker-2.3.8.jar• ognl-2.6.11.jar• struts2-core-2.0.12.jar• xwork-2.0.6.jar
  • 13. Example program using strutsWe suppose to create a login application using struts.
  • 14. Getting started• Open eclipse and go to fileNewDynamicproject in the new project wizard screen.• You will have a screen consisting of somewizards as shown in the next slide.• After giving the project name click Finish.
  • 15. Getting started
  • 16. Getting started• Once you created the project, you can see itsstructure in the project folder.• After these processes, now copy all the jarfiles listed in the previous slides toWebContentWEB INF
  • 17. Structure of project folder
  • 18. Import jar files
  • 19. Mapping program to xml• Open web.xml file which is under WEB-INFfolder and copy-paste the following program.
  • 20. Mapping program to xml• <?xml version="1.0" encoding="UTF-8"?>• <web-app id="WebApp_9" version="2.4"• xmlns="http://java.sun.com/xml/ns/j2ee"• xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"• xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">•• <display-name>Struts2 Application</display-name>• <filter>• <filter-name>struts2</filter-name>• <filter-class>• org.apache.struts2.dispatcher.FilterDispatcher• </filter-class>• </filter>• <filter-mapping>• <filter-name>struts2</filter-name>• <url-pattern>/*</url-pattern>• </filter-mapping>• <welcome-file-list>• <welcome-file>Login.jsp</welcome-file>• </welcome-file-list>•• </web-app>
  • 21. Class and methods• Create a class called LoginAction incom.test.struts2package.• Note that, above action class contains two fields, username andpassword which will hold the values from form and also contains anexecute() method that will authenticate the user. In this simpleexample, we are checking if username is admin and password isadmin123.• Also note that unlike Action class in Struts1, Struts2 action class is asimple POJO class with required attributes and method.• The execute() method returns a String value which will determinethe result page. Also, in Struts2 the name of the method is notfixed. In this example we have define method execute(). You maywant to define a method authenticate() instead.
  • 22. Create resource file• Resource bundle is a java entity that helps inputting the static content away from thesource file.• Here we should define an application file andshould be named asApplicationResources.properties files• To create it the method is on the next slide
  • 23. Resource folder
  • 24. Resource folder• Click that source folder option and you will behaving a following screen.• And set the source folder as Resources folder.• In that folder create a file calledApplicationResources.properties .
  • 25. Resources• Copy these contents intoApplicationResources.properties• label.username= Username• label.password= Password• label.login= Login• error.login= Invalid Username/Password. Please try again.
  • 26. Jsp files to run the applicationLogin.jsp
  • 27. Jsp files(2)Welcome.jsp
  • 28. Jsp(3)• Above programs are made in the folderStruts2_HelloworldWebContentWEB-INFLogin.jsp.• Struts2_HelloworldWebContentWEB-INFWelcome.jsp.
  • 29. Create a struts file• Struts2_HelloWorldJavaResourcesresourcescreate file struts.xml• Copy the following content into struts.xml
  • 30. Struts.xmlCopy the above text into struts.xml.
  • 31. Important note• Our LoginAction.java class is having a methodcalled execute(). If the name of the method isdifferent, e.g. authenticate(). Then we shouldspecify the name of the method in the actiontag.
  • 32. Action• You can see <s: submit method command inthe program Login.jsp
  • 33. Running the application• Now select Login.jsp then select the run onserver command.• After selecting the command, you will behaving a server lists out of that, select apache-tomcat server version.6. then run theprogram.• You will be having the following screen onyour browser.
  • 34. Screens(1)Enter user_name as admin and password as admin123
  • 35. Screen(2)If you login successfully, you will get a screen as output.
  • 36. Screen(3)If you login into the application as a wrong user, the appearing screen will belike this. You are instructed to renter the user and password again
  • 37. If this presentation helped you, please visit ourpage facebook.com/baabtra and like it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com
  • 38. Contact UsEmarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550Start up VillageEranakulam,Kerala, India.Email: info@baabtra.com

×