Skip navigation.
Home

Struts

The goal of the Apache Struts project is to encourage application architectures based on the "Model 2" approach, a variation of the classic Model-View-Controller (MVC) design paradigm. Under Model 2, a servlet (or equivalent) manages business logic execution, and presentation logic resides mainly in server pages.\\ \\ The Apache Struts project encourages Model 2 designs in two ways. First, by providing open source frameworks and toolkits that help developers build applications for the web. Second, by providing friendly and honest mailing lists where both newcomers and veterans discuss how to use Struts software in their own Model 2 applications.\\ \\ Originally, the Apache Struts software was distributed as one monolithic bundle. Today, the Apache Struts project is comprised of two distinct frameworks and several other subprojects. The two frameworks are the Struts Action Framework and the Struts Shale Framework. Struts Action is the original request-based framework. Struts Shale is a component-based framework based on JavaServer Faces. Both frameworks are first-class citizens of the Apache Struts project.\\ \\ !!Struts Sample *[Install Tomcat|http://www.egjug.org/?q=tomcat_linux] *Create Application Directory After installing tomcat you should create a directory for your application to add the files you will create. In the tomcat directory you will find the __webapps__ directory like that "jakarta-tomcat-5.0.28\webapps" create a directory for your project called __StrutsProject__ and this folder will contain your files and folders. Your web application Should be like webapps | | StrutsProject | |---- java | --- src | --- org | -- egjug | --- WEB-INF | |--- classes | |--- lib *Add Struts Files and Libraries Struts framework require some libraries to be included in your project like: **commons-beanutils.jar **commons-digester.jar **jstl-1.1.1.jar **standard-1.1.1.jar **struts.jar Those files will be located under the __lib__ folder *Edit your web.xml *Create struts-config.xml *Create Your JSP Pages *Create Action Forms *Create Action Class *Edit struts-config.xml *Test your application !!Struts Tips *__Using tag:__ Using this tag, struts will render your page as XHTML. In My opinion, writing XHTML is the right thing to do. *__Using tag:__ As you know, Struts framework come with a set of html tags which encapsulate too many functionalities. ;__Using attributes from Action form__: You can use the setter & getter in the action form in your jsp code wheather you are using Struts HTML or JSTL. Simply write the name of the attribute and Struts will call the getter for you. What if you want to call a function? if the function called getXXX and XXX is not an attribute in the form bean, just call the xXX and Struts will do it also. Wonderfull!, but what if i have a function return boolean called isYYY will struts do it also? YES. ;__Forwarding to an Action in Another web context__: if you have 2 web application in the same project and produce 2 war or ear file how can you forward from action to another? Simply you will make the following code {{{ getServlet().getServletContext().getContext("/Webapp2").getRequestDispat cher("/action22.do").forward(request, response); }}} __Resources:__ *Struts Main Site http://Struts.apache.org *Struts Wiki http://wiki.apache.org/struts/ *[Beginer Tutorial|http://www.isabelle-hurbain.com/doc/struts.html]