Академический Документы
Профессиональный Документы
Культура Документы
CONTROLLER COMPONENTS
• Controller Mechanism
• ActionServlet class
• RequestProcessor class
• Action class
• Action Forward class
• Plugin
• A Controller is a Browser
• ActionServlet
– Main controller and responsible for receiving all Http requests and
initializing Struts framework for a web application
• RequestProcessor
– Used to process the requests received by the ActionServlet
• Action
– Implements each type of request received. Actually creates a wrapper
around the business logic
• ActionForward
– Responsible for identifying where the control should be forwarded to
provide an appropriate response
• Plugin
– Used to provide same specific functionality at startup and shutdown of
the web application.
org.apache.struts.action.ActionServlet
extends javax.servlet.http.HttpServlet
• public void init()
– Called by Servlet Container for the first time when
the servlet is invoked and before any other request is
processed
• public void doGet (request, response)
– Process an HTTP ‘GET’ request
• public void doPost (request, response)
– Process an HTTP ‘POST’ request
ActionServlet
Mapping
<url-pattern> <servlet-class>
</url-pattern> </servlet-class>
• Extends org.apache.struts.action.Action
• Overrides the execute()method
• Acts as a bridge between user-invoked URI and a
business method (Command pattern)
• Returns information about which view should be
rendered next
• Part of the Controller, not the Model
• ForwardAction
• DispatchAction
• LookupDispatchAction
• MappingDispatchAction
• IncludeAction
• SwitchAction
• LocaleAction
• forward Tag
– The code declares forward in struts configuration file.
< action-mappings>
<action path = "/updateCustomer" Type = "com. Struts
example.customer. UpdateCustomer ">
forward name = "Success" path = "/updateCustomer.jsp"/>
</action>
< /action-mapping>
• The code in the code snippet defines a URL to be used as forward with
local scope. Here, the action will be forwarded to the updateCustomer
page whenever the forward named "Success" is found.
• Model Components
• View Components
• Struts Tag Library
• Struts and
Internationalization
• JavaServer Pages
• HTML
• JavaScript and Stylesheets
• Multimedia Files
• Resource Bundles
• JavaBeans (Part of model used by views)
• JSP Custom Tags
• ActionForms
ActionForm
validate() ActionForm Class
reset() acts as buffer and
holds state of data
}
return errors;
}
<validator name="email"
classname="org.apache.struts.validator.FieldChecks"
method="validateEmail"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.email"/>
Include
Tag Tag Application directives
Handler Library deloyment For Tag
descriptor descriptor Libraries
TAG LIBRARY
• Tag library
– HTML Tag Library
– Bean Tag Library
– Logic Tag Library
<taglib>
<taglib-url>/WEB-INF/tlds/struts-logic.tld</taglib-url>
<taglib-location>/WEB-INF/tlds/struts-logic.tld
</taglib-location>
</taglib>
iterate Repeats the nested body content of this tag over a specified collection.
greaterEqual Checks if the variable specified by any one of attributes cookie, header, name, parameter, or
property is greater than or equal to constant value specified by value attribute.
match Checks if the variable specified by any one of the attributes cookie, header, name, parameter,
or property contains specified constant value.
messagesPrese Generates the nested body content of this tag if specified message is present in this request.
nt
present Checks if the variable specified by any one of attributes cookie, header, name, parameter, or
property is present in the applied scope.
ACCPi7.1, AWAJS- Architecting Web Applications using JSF and Struts
44
Bean Tag Library
<taglib>
<taglib-url>/WEB-INF/tlds/struts-logic.tld</taglib-url>
<taglib-location>/WEB-INF/tlds/struts-bean.tld
</taglib-location>
</taglib>