Struts: JSP, Form and Action relationship
1. Create: (or convert an HTML page) JSP page (Presentation layer on Browser) (using struts tags) add at least these 3 struts tag libraries at top before the <html> tag: <%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic" %> sometimes this one too: <%@ taglib uri="/WEB-INF/taglib/struts-nested.tld" prefix="nested" %> may need tags more - at times... change any <form> tags to <html:form action="/listSomething" method="get"> (must be the same as <action path="/" in struts-config) add tags to view data held in ValueObject <bean:write name="someValueObject" property="someFieldName"/> 2. Create: Form Class (Form.java) (Form.class runs on Server) <form-bean .../> extends from ActionForm (a struts class) *default constructor sop("—someForm.constructed()—"); *overwrite validate(); (for form level validations) preValidate(request); (if needed) ActionErrors errors = new ActionErrors(); return errors; *overwrite toString(); (if needed...) *someValueObject (declare instance variable of ValueObject, populate it with values from browser or database) *setters and getters for each parameter used someValueObject.fieldNames (parameters used/passed) action 3. Create: Action Class (Action.java) (Action.class runs on Server) extends from Action (a struts class) *overwrite execute(); (core of the code...) sop("—someAction.execute()—"); ActionForward forward = null; SomeForm someForm = (SomeForm)form; String action = someForm.getAction(); forward = mapping.findForward("nextPage"); (same as in <forward name="nextPage" in <action-mappings>) return forward; -Business rules (for business logic validations) -Database connections & actions (get/sets from SomeHandlerImpl.java using SomeValueObject.java) 4. Define <form-bean name="someForm".../> in struts-config.xml 5. Define <action-mapping> <action path="" name="someForm" <forward name="nextPage" in struts-config.xml (<form-bean name="" must be exactly the same as <action name="") struts-config.xml "ties" 1-3 together with 4&5
More information: Apache struts , struts-api , java-api , struts-html , struts-bean , struts-logic , Husted struts , KeyBoardMonkey




