This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
• ourses eve ope an aug y ar y a – Java 6, servlets/JSP (intermediate and advanced), Struts, JSF 1. x , JSF 2.0, Ajax, GWT 2.0 (with GXT), custom mix of topics
– Ajax courses can concentrate on 1 library (jQuery, Prototype/Scriptaculous, Ext-JS, Dojo, Google Closure) or survey several
• Courses developed and taught by coreservlets.com experts (edited by Marty) – Spring, Hibernate/JPA, EJB3, SOAP-based and RESTful Web Services, Ruby/Rails
• An MVC Framework? – ru s prov es a un e ramewor or ep oy ng serv e
and JSP applications that use the MVC architecture.• A Collection of Utilities? – Struts provides utility classes to handle many of the most
common tasks in Web application development
• – Struts provides custom tag libraries for outputting bean
properties, generating HTML forms, iterating over ,
outputting HTML.
• But which is the proper way to view Struts? – The answer depends on what you are going to use it for,
but the MVC framework is the most common way of looking at Struts.
6
Advantages of Struts (vs. MVC
• Centralized file-based configuration – - ,
Struts values are represented in XML or property files. This loosecoupling means that many changes can be made without modifyingor recompiling Java code, and that wholesale changes can be made
.developers focus on their specific tasks (implementing businesslogic, presenting certain values to clients, etc.) without needing to
know about the overall system layout.• orm eans – In JSP, you can use property="*" with jsp:setProperty to
automatically populate a JavaBean component based on incomingre uest arameters. A ache Struts extends this ca abilit to Java code and adds in several useful utilities, all of which serve to greatlysimplify the processing of request parameters.
• Bean tags – pac e ru s prov es a se o cus om ags ean:wr e, n
particular) that let you easily output the properties of JavaBeanscomponents. Basically, these are concise and powerful variations of the standard jsp:useBean and jsp:getProperty tags.7
• HTML tags – Apac e Struts prov es a set o custom JSP tags to create HTML
forms that are associated with JavaBeans components. This bean/form association serves two useful purposes:
• - .
• It lets you redisplay forms with some or all previously enteredvalues intact.
• – Apache Struts has builtin capabilities for checking that form values
are in the required format. If values are missing or in an improper orma , e orm can e au oma ca y re sp aye w error
messages and with the previously entered values maintained.
• This validation can be performed on the server (in Java), or both.
• Consistent approach – Struts encourages consistent use of MVC throughout your app.8
Disadvantages of Struts (vs.
• Bigger learning curve – o use w e s an ar eques spa c er, you
need to be comfortable with the standard JSP and servletAPIs. To use MVC with Struts, you have to be
large and elaborate framework that is almost equal in sizeto the core system. This drawback is especially
si nificant with smaller ro ects near-term deadlines andless experienced developers; you could spend as muchtime learning Struts as building your actual system.
• Worse documentation – Compared to the standard servlet and JSP APIs, Struts
has fewer online resources, and many first-time users findthe online A ache documentation confusin and oorlorganized. There are also fewer books on Apache Strutsthan on standard servlets and JSP.
• Main API (JavaDoc) – http://struts.apache.org/struts-action/apidocs/
• User’s Guide – ttp: struts.apac e.org struts-act on user u e
• Alternative for main API: read a local copy – ,
date. To read a local copy, install thestruts-documentation.war Web app. Copy struts_insta _ ir we apps struts- ocumentat on.war totomcat_install_dir /webapps, restart server, and use theURL http://localhost/struts-documentation/.
18
Testing Struts in an IDE
• Install the struts-blank project• ee p: courses.coreserv e s.com ourse- a er a s s ru s. m
• Deploy the project (Eclipse)
– De lo ro ect• Select “Server” tab at bottom, R-click on Tomcat, Choose “Add
and Remove”, Choose project, Click “Finish”
– Start Tomcat• Select “Server” tab at bottom, R-click on Tomcat, Choose “Start”
• Open browser and enter http://localhost/struts-blank/
• Will redirect to http://localhost/struts-blank/Welcome.do
• Deploy the project (JDeveloper ) – Right-click on WebContent/index.jsp and select “Run”
–
– Will redirect to http://localhost/struts-blank/Welcome.do
• Install struts-blank.war. – Install the Web application from
struts_install_dir /webapps/struts-blank.war on your server. For example, with Apache Tomcat, copy struts_install_dir /webapps/struts-blank.war totomcat_install_dir /webapps/.
• . – Most servers only recognize new Web apps when the
server is started.
• Access http://localhost/struts-blank/.
– Will redirect to http://localhost/struts-blank/Welcome.do –
desktop and are using port 80. In general, accesshttp://hostname: port /struts-blank/.