Anti-Patterns:
Concern Slush
Different tiers (presentation, business, and data logic) are not clearly separated.
Tier Leakage:
A tier is allowed to access another tier not immediately adjacent to it.
Hardwiring
Need to search through all source code to change a link or change application workflow.
Validation Confusing
Tight-Skin
Data Madness
Setting up for Struts
- In JSP page, include Struts tag library struts-form.tld, create prefix
- Set action to *.do
- Set properties for actions
- Properties will be picked up by ActionForm derived class
MVC Model
- org.apache.struts.action.ActionServlet is set to be the default servlet. URL pattern mapped to servlet is usually *.do. Mapping is done in web.xml.
- Set main configuration file, typically struts-config.xml, in param-name property config for the servlet.
- Main configuration file contains all form-beans and action-mappings.
- Action derived classes call ActionMapping.findForward to redirect page.
- The servlet, ActionServlet, acts as the controller, taking user request and maps it to an action mapping
Sequence of events
- index.jsp is called, page forwards to Welcome.do
- Welcome.do is a virtual, and struts-config.xml maps it to welcomeStruts.jsp
- index.jsp is called, page contains action login.do, which maps to /login, loginForm, and struts.LoginAction
- loginForm is a Form Bean, which maps to struts.LoginForm
- LoginForm is a POJO providing a backing object to the form properties
- LoginAction derives from Action. It contains the logic that determines whether the forward page will be “success” or “failure”
- “success” and “failure” are properties of LoginAction mapping to htmls.