The following Figure shows how a request flows through the Struts framework. Follow step by step....
Step 1. The request calls the ActionServlet with a certain logical input form name.
Step 2. This logical form name is then resolved according to mapping entries defined in action.xml. This file contains the mapping that defines which Struts components are associated with which logical form.
Once the mapping is resolved, the ActionServlet will look in the session for the ActionForm class associated with the request. If such a class is located in the session, the ActionForm attributes are populated by calling the corresponding setter methods. However, if the ActionForm is not located in the session, a new instance is created and added to the user’s session. Subsequently, the reset method is called on the action form and the ActionForm attributes are populated.
Step 3/4. Next, the ActionServlet calls the validate method on the ActionForm. The validate method returns either null (indicating success) or an array of errors (indicating an error condition). If the ActionForm’s validate method returns an array of errors, the ActionServlet populates the requesting input form and displays the errors to the user. we can disable the call to this method if we define validate=false in struts config file. we can disable the validate for all the action forms if we define init parameter validate with value false in web.xml for ActionServlet(Controller).
Step 5. Once the validate method returns null, the ActionServlet will instantiate an instance of ActionClass (if one does not already exist) as indicated by the mapping in action.xml. The ActionClass execute method is then invoked by ActionServlet. The execute method is responsible for processing the request.
Step 6. The execute method is required to return an ActionForward instance. This instance indicates to the ActionServlet which JSP (if any) to forward the request off to for rendering of the presentation.
Step 7. The JSP is responsible for generating the appropriate response based on the results of executing the execute method. In Struts, an ActionForm bean has only one purpose -- to represent the last input state of all the user's entries on a particular form. the ActionForms are also called the transfer objects between the controller and the Views because they carry the values from controller (Action) to the Views (Jsp).
That way, the framework can easily redisplay the last input screen (plus some error messages) pre-populated with what the user last entered, which is what anyone who has ever used a GUI application expects.
May be the request processing seems to be complex at first sight, but once you are acquinted with it...it would put you one the drive!!!!. Enjoy Struts!!!!!
Monday, 30 April 2007
Struts Request Processing illustration, the first sight...
Struts 2 : features and short summary
The strut-2 framework is designed for the compilation of the entire development cycle including of building, developing and maintaining the whole application. It is very extensible as each class of the framework is based on an Interface and all the base classes are given an extra application and even you can add your own. The basic platform requirements are Servlet API 2.4, JSP API 2.0 and Java 5.
Some of the general features of the current Apache Strut 2 framework are given below.
Architecture – First the web browser request a resource for which the Filter Dispatcher decides the suitable action. Then the Interceptors use the required functions and after that the Action method executes all the function like storing and retrieving data from a database. Then the result can be seen on the output of the browser in HTML, PDF, images or any other.
Tags - Tags in Strut 2 allow creating dynamic web application with less number of coding. Not only these tags contain output data but also provide style sheet driven markup that in turn helps in creating pages with less code. Here the tags also support validation and localization of coding that in turn offer more utilization. The less number of codes also makes it easy to read and maintain.
MVC – The Model View Controller in Strut 2 framework acts as a co-coordinator between application’s model and web view. Its Controller and View components can come together with other technology to develop the model. The framework has its library and markup tags to present the data dynamically.
Configuration – Provides a deployment descriptor to initialize resources and is in XML format. The initialization is taken place by scanning all the classes using Java packages or you can use an application configuration file to control the entire configuration. Its general-purpose defaults allow using struts directly Out of the box.
Configuration files are reloadable that allows changes without restarting a web container.
Other Features:
- All framework classes are based on interfaces and core interfaces are independent from HTTP.
- Check boxes do not require any kind of special application for false values.
- Any class can be used as an action class and one can input properties by using any JavaBean directly to the action class.
- Strut 2 actions are Spring friendly and so easy to Spring integration.
- AZAX theme enables to make the application more dynamic.
- Portal and servlet deployment are easy due to automatic portlet support without altering code.
- The request handling in every action makes it easy to customize, when required.
Struts 2 History
Apache Struts is an open-source framework that is used for developing Java web application. Originally developed by the programmer and author Craig R. McClanahan this was later taken over by the Apache Software Foundation in 2002. Struts have provided an excellent framework for developing application easily by organizing JSP and Servlet basically based on HTML formats and Java code. Strut1 with all standard Java technologies and packages of
Strut is a well-organized framework based on MVC architecture. In Model-View-Architecture, Model stands for the business or database code, the View represents the page design code and the Controller for navigational code. All these together makes Struts an essential framework for building Java application. But with the development of new and lightweight MVC based frame works like Spring, Stripes and Tapestry, it becomes necessary to modify the Struts framework. So, the team of Apache Struts and another J2EE framework, WebWork of OpenSymphony joined hand together to develop an advanced frame works with all possible developing features that will make it developer and user friendly.
Strut2 is a combined features of Struts Ti and WebWork 2 projects that advocates higher level application by using the architecture of WebWork2 with features including a plugin framework, a new API,
Struts 2 Architecture
Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework.
Request Lifecycle in Struts 2 applications
- User Sends request: User sends a request to the server for some resource.
- FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.
- Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
- Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving the data from database.
- Output rendering: Then the Result render the output.
- Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.
Struts 2 Architecture
Struts 2 is very elegant and flexible front controller framework based on many standard technologies like Java Filters, Java Beans, ResourceBundles, XML etc.
For the Model, the framework can use any data access technologies like JDBC, EJB, Hibernate etc. and for the View, the framework can be integrated with JSP, JTL, JSF, Jakarta Velocity Engine, Templates, PDF, XSLT etc.
Exception Handling:
The Struts 2 Framework allows us to define exception handlers and inceptors.
- Exception Handlers:
Exception handlers allows us to define the exception handling procedure on global and local basis. Framework catches the exception and then displays the page of our choice with appropriate message and exception details.
- Interceptors:
The Interceptors are used to specify the "request-processing lifecycle" for an action. Interceptors are configured to apply the common functionalities like workflow, validation, etc.. to the request.
Struts 2 Architecture
The following diagram depicts the architecture of Struts 2 Framework. Following diagram shows the the initial request goes to the servlet container such as tomcat, which is then passed through standard filer chain.
Image: Struts 2 Architecture
The filter chain includes:
- Action ContextCleanUp filter:
The ActionContextCleanUp filter is optional and it is useful when integration has to be done with other technologies like SiteMash Plugin.
- FilterDispatcher:
Next the FilterDispatch is called, which in turn uses the ActionMapper to determine weather to invoke an Action. If the action is required to be invoked, the FilterDispatcher delegates the control to the ActionProxy.
- ActionProxy:
The ActionProxy takes the help from Configuration Files manager, which is initialized from the struts.xml. Then the ActionProxy creates an ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action. The the ActionInvocation looks for proper result. Then the result is executed, which involves the rendering of JSP or templates.
Then the Interceptors are executed again in reverse order. Finally the response returns through the filters configured in web.xml file. If the ActionContextCleanUp filter is configured, the FilterDispatcher does not clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present then the FilterDispatcher will cleanup all the ThreadLocals present.
In this section we have learned about the Architecture of Struts 2 Framework.
Download Struts 2.0
In this section we will download and install the Struts 2.0 on the latest version of Tomcat container. We will first download tomcat and configure it as our development server. Then we will download Struts 2.0 and install the struts-blank application on the tomcat server server to check the examples that comes with the struts-blank application.
Downloading Struts 2.0
Visit the Struts download site http://struts.apache.org/download.cgi and download the Struts 2.0 for this tutorial.
Download the Tomcat
Extracting Struts 2.0 distribution and installing on tomcat
Extract the downloaded struts distribution struts-2.0.6-all.zip into your favorite directory. To install the struts blank application copy "struts2-blank-2.0.6" from "
Feb 25, 2007 11:42:23 PM org.apache.coyote.http11.Http11BaseProtocol start |
To test the struts-blank application type http://localhost:8080/struts2-blank-2.0.6 in the browser and the struts-blank application get displayed in your browser window.
Click the English link and familiarize yourself with Struts Blank sample application.
Struts 2.0 distribution also contains the following samples applications that you can try:
- struts2-mailreader-2.0.6.war
- struts2-portlet-2.0.6.war
- struts2-showcase-2.0.6.war
You can simply copy these files to the webapps directory of your tomcat server. Tomcat will automatically deploy these application and then you can test these applications.
Sunday, 29 April 2007
Sun Certified Java Programmer (SCJP) Free Mock exams
List of 40+ Free sites, Where core java mock exams are free online. These sites can help individuals in preparing for Sun Certified Java Programmer (SCJP) exam and the core java interview questions.
If you want to revise your java skills before taking these mock exams , then go to jchq essentials first. Please follow the link.....
http://www.jchq.net/essentials/index.htm#full
And here goes the site lists..... cheers guys!!!!- Sun's sample questions:
- Java Ranch Rules Round Up Game: 36 questions. Basic questions, but important for certification.
- Jaworski: Java quiz with answers. Very useful
- Robert and Heller's Online Self Test: 10 questions.
- Absolute Java's Test Your Java Knowledge: 17 questions on variety of topics
- Java Prepare Questions: 59 questions.
- John Hunt Mock exam: 65 questions, Simple
- Java Caps Mock exam: 60 questions with answers
- Marcus Green mock exam - 1: 60 questions.
- Marcus Green mock exam - 2: 60 questions. Highly recommended
- Marcus Green mock exam - 3: 60 questions.
- MindQ exam: Good one.
- Majji exam: 30 questions, Very good.
- Amit Poddar's questions: 42 questions, related to Strings, Components and Layouts and Math class
- IBM online exam tool: 30 questions
- Barry Boone Exam: 70 questions.
- Bill Brogden exam: Random 18 from 38 questions.
- Bill Brogden's Hardest questions: 19 questions, If you want to waste your time
- Jxam: 59 from 200 questions.
- Sarga's Jargon Exam: 60 questions from 140 questions.
- JQuest Exam simulator: 30 from 90 questions.
- JDcert: 66 questions, Simple
- Deepak exam site: 250 questions.
- Applied Reasoning Exam: 77 questions, generated from a pool of 200 questions.
- Boris's Exam Simulator: 40 questions from 64 questions.
- Abhilash's Quiz: 80 questions with answers.
- Java Exam Simulation - Test 1: 30 questions.
- Java Exam Simulation - Test 2: 59 questions.
- Java Exam Simulation - Test 3: 59 questions.
- Java Exam Simulation - Test 4: 59 questions.
- Java Exam Simulation - Test 5: 128 questions.
- Exam Cram Pratice Exam 34 questions.
- 4tests.com's Java Exam: 40 questions.
- JvalTest Exam Applet: 60 questions.
- Mughal Khalid's Exam Simulator: 60 questions,
Tough in comparison to the actual certification exam. - JWhizTrial Exam
These are sample questions from the actual software. Need to download them to your computer. - Java Exam Simulator .
- Rahul Raje's Mock Exam Simulator : 60 questions. Needs downloading and extracting jar files
- http://www.go4java.20m.com/mock1.htm : 2 mock exams with 59 questions each.
- Web Tech Frontier : 56 Questions.
- Voodoo Exam by Ashish Hareet : At the time of writing this page, the mock exam has 60 questions related to SCJP.
About.com Java certification links
Abhinav Gupta's Guide to Certification
Amit Verma's Certification Page
Ashok Kumar's Java section
Bill Brogden's Java Resources
Chitra Sridhar's Java Site
Certify in Java Resources
Deepak's Certification Page
Dave's Java Site
Dasari's Java Certification Page
Javaranch
Java Prepare
Jyothi Krishnan's Java Page
Java Caps
Jxam Homepage
Java China Page
Java Certified Programmer Resources
Valiveru's Homepage
Java Skinny
Kaan
Levteck Java site
Maha Anna's Java Home page
Marcus Green Certification Headquarter
Michael Thomas Java Certification and Training Page
Mukherjee's Java Page
Moogly-googly
Sun Certification Site
Tony Alicea's Java Page
Usha Kasiram SCJP Resources
I recently found the following site having similar SCJP Mock exams links. Have a look if you find some useful or new stuff.
http://www.javacertificationexams.com/scjp-mock-exams.php
Secrets Of The Masters: Core Java Job Interview Questions.
JDJ Enterprise Editor Yakov Fain Offers 30 Core Java Questions You Might Expect During Job Interviews. Good 20 ones in the list anyways.