[READ: Why-JAVA][Start-Learning-JAVA][Why-Java's-Hot][Start-Using-LINUX][Java-Q-&-A][Question][Java-SE-6-Doc][Struts-Doc][Java-Tutorial-Index] [Java-Certification]
[Tech.][Struts.][Servlet.][JSP.][EJB.][JNDI-JMS][SQL.][JDBC.]
CORE-JAVA: [OOP][CLASS][ABSTRACT][EXCEPTIONS][THREADS][UTILS][PACKAGES][JVM][CASTING][NETWORKING][RMI-XML]
[Tech.][Struts.][Servlet.][JSP.][EJB.][JNDI-JMS][SQL.][JDBC.]
CORE-JAVA: [OOP][CLASS][ABSTRACT][EXCEPTIONS][THREADS][UTILS][PACKAGES][JVM][CASTING][NETWORKING][RMI-XML]
How STRUTS Works? (Steps Involved in the process.) (Tutor) (API Doc)
* Client request is handled by ActionServlet. (Controller) (Questions)
* Requested page (Ex: Login.jsp) is produced to client. (Intro to Struts: Ex)
* Login.jsp page contains html:form tag, to collect the client entered data. (Tag Lib Doc)
* struts-config.xml file has "action-mappings" element to specify action bean.
* struts-config.xml file has "form-beans" element to specify the form bean.
* struts-config.xml file has "plug-in" element to specify the validator bean (Ex: validator-rules.xml and validator.xml).
* The form data entered by client is populated in ActionForm.
* Server container invokes "Action" bean's execute method to return "ActionForward" object.
* Action beans "execute()" method initializes "HttpSession" object using "HttpRequest" object. Then, retrieves values from the FORM bean by creating the object. Creates "Serializable" object after retrieving the data from database. Assigns it to "setAttribute" method of session object for later retrieval.
Steps involved in data retrieval from database, in STRUTS.
(1) Use "InitialContext" to create "Context" Ex: Context ctx = new InitialContext();
(2) Use "Context" to create DataSource Ex: DataSource ds = (DataSource) ctx.lookup(jdbc/oracleds");
(3) Use "DataSource" to create "Connection" Ex: Connection con = ds.getConnection();
(4) Use "Connection" to create "Statement" Ex: Statement stmt = con.createStatement();
(5) Use "Statement" to create "ResultSet" Ex: ResultSet rs = stmt.executeQuery(String);
(6) Use "ResultSet" to create "String" Ex: String str = rs.getString(No.#);
(7) Use "String" to create "User Object" Ex: UserObject user = user.setUserId(str);
(Note: Changes from step "4" onwards.)
Steps involved in creating "CallableStatement insted of "Statement". (for Stored Procedures)
(4) Use "Connection" to create "CallableStatement" (Ex:)
Ex: CallableStatement cstmt = con.prepareCall("{call myProc}"); // String
cstmt.registerOutParameter(1, OracleTypes.CURSOR); // this # is later passed in getObject parameter.
(5) Use "CallableStatement" to create "ResultSet"
Ex: ResultSet rs = cstmt.getObject(No.#); // # of cstmt.registerOutParameter
(6) Use "ResultSet" to create "String" Ex: String str = rs.getString(No.#);
(7) Use "String" to create "Array List Object" Ex: ArrayList alist = alist.add(Object);
Theory: There are two "configuration files" in struts applications.
(1) Web application deployment descriptor (web.xml) (Directory Structure)
(2) Struts configuration file (struts-config.xml) (Apache Guide)
Web.xml: This is placed in WEB-INF directory. This is used by web container on startup to configure the runtime environment. (Example) (Apache)
Element "servlet-class" is used to specify ActionServlet, which acts as a controller.
Element "url-pattern" *.do is used to specify that url mapping with *.do will be processed by ActionServlet.
Element "init-param" is used to specify the struts-config.xml used to config runtime environment. “Initialization parameters” Ex: "init-value" "param-value" *.xml.
Element "load-on-startup" No.# directs the web container to initiate an instance of init() method of servlet. The integer value specifies the order in which the servlet is called. A negative value indicates container to load in any order.
Element "welcome-file-list" specifies the starting page for web application.
Element "tag-lib" specifies JSP tag libraries to use in JSP files, which helps the container to find descriptor tld files. Ex: struts-html.tld, struts-bean.tld, struts-logic.tld, etc. (Tag Lib Doc)
Struts-config.xml: This is used by struts framework to configure the application. This is a default name, and can be changed in web.xml file. Its normally placed in WEB-INF directory. We can also use more than one struts-config.xml files. Ex: "param-name" struts-config.xml, struts-config2.xml etc.
Element "data-source" is used to setup data source for struts framework. It contains multiple (set-property property="_" value="_") elements. Property attribute is name of setter method. Value attribute is value passed to setter method.
Element "form-beans" is used to configure ActionForm to be used in Action class. Within this element multiple elements of "form-bean" can be configured.
Element "global-exception" is used to configure exception handling.
Element "global-forwards" is used to forward an action to a view. It contains multiple "forward" elements (this can also be in action element). If the forward name is same in both places then action level takes precedence.
Element "action-mapping" is used to map Action class to request path. It may contain multiple action elements. (ActionMapping)
Element "message-resources" is used to specify the "*.properties" file, which contains text messages. (MessageResources)
What is Jakarta Struts Framework?
A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
What is Struts?
A: The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Common packages.
Struts encourages application architectures based on the Model 2 approach, a variation of the classic Model-View-Controller (MVC) design paradigm.
Struts provides its own CONTROLLER component and integrates with other technologies to provide the Model and the View.
For the MODEL, Struts can interact with standard data access technologies, like JavaBeans, JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge.
For the VIEW, Struts works well with JavaServer Pages (JSP), including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems. The Struts framework provides the invisible underpinnings every professional web application needs to survive. Struts helps you create an extensible development environment for your application, based on published standards and proven design patterns.
(Hibernate-Intro) - (Hibernate-Xml-Mapping) - (Hibernate-Questions) - (Struts-Plugin) - (Example)
What is ActionServlet?
A: The class (org.apache.struts.action.ActionServlet), in the Jakarta Struts Framework plays the role of a controller. All the client requests to the server are handled by this controller.
How you will make available any Message Resources Definitions file to the Struts Framework Environment?
A: The Message Resources Definitions file are simple "*.properties" files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through tag "message-resources".
What is Action Class?
A: The Action Class is part of the MODEL and is a wrapper around the business logic. To use the Action, we need to Subclass and overwrite the execute() method. All the database/business processing are done in the Action Class.
execute method returns: ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) (Example) (Intro to Struts)
{
String pwd = form.getPassword(); /* Retrive value from ActionForm */
/* validate this pwd in database and assign "result" as "success" or "failed" */
return mapping.findForward(String result); /* ActionForward object */
}
The return type of the execute method is ActionForward which is used by the Struts Framework (struts-config.xml) to forward the request to the VIEW file.
What is ActionForm?
A: An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from the client side VIEW form. (Example)
What is Struts Validator Framework? (Ex: Intro to Struts)
A: Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used to validate the form data on the client browser. Server side validation of form can be accomplished by sub classing the FormBean with DynaValidatorForm class. (Dyna Ex.) (Ex:2) (Code:1) (Code:2)
The Validator framework was developed as a third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
Give the Details of XML files used in Validator Framework? (Intro) (Guide)
A: The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean. Validation.xml defines mapping for client entered string data. Validator-rules.xml defines mapping for the ClassName used to process the data.
How you will enable front-end validation based on the xml in validation.xml?
A: Specify parameter values of VIEWform in validation.xml and add the below code in the VIEW file.
"html:javascript formname='VIEWform' dynamicjavascript='true' staticjavascript='true' "
This generates the client side java script as defined in the validation.xml. [Article]
How to get data from the velocity page in a action class? (Velocity) (Overview)
A: We can get the values in the action classes by using data.getParameter(\"variable name defined in the velocity page\");
Velocity separates Java code from the web pages. It's an alternative to JSP. It permits web page designers to reference methods defined in Java code. (What is Velocity?)
some More good ones Here: Friendship
Here is something nice to motivate:
[Let’s-make-it-happen.][Someone-Somewhere.][Logic-of-Good-and-Bad.][Only-One-I-have-got.]
[Faith-in-Patience.][Ingredients-of-Super-Power.][Successful-Life.][Amazing-Constructive-Vibrations.]
* * ** * * *
"WE" has More Power than "I". Please leave a comment if you encounter any problems or have any suggestions.
Life is Beautiful.
Creating-successful-constructive-personality. Why-God-Gave-Us-Friends? Way-to-Paradise. Creating-the-Beautiful-World. Doing-the-job-of-goodness. Life-is-Meaningful. The-A-to-Z-for-Goodness. Life-is-full-of-Tests. History-Proves-That. Love-in-different-forms. True-to-the-heart.
No comments:
Post a Comment