1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * A simple Action for Checkbox test. * * @author Danilo Gurovich */ public final class CheckboxTestAction extends Action { // -------------------------- OTHER METHODS -------------------------- /** * The execute method * * @param mapping ActionMapping * @param form CheckboxTestForm * @param request HttpServletRequest * @param response HttpServletRespons * @return success to the confirmation page * @throws ServletException not thrown, but could be! * @throws Exception ditto. */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, Exception { // Extract attributes needed String[] selectedMountains = ((CheckboxTestForm) form).getSelectedMountains() ; System.out.println("htmlString RETURNED*\n" + selectedMountains.toString()); //Save the htmlString in the session for later... HttpSession session = request.getSession(); session.setAttribute(CheckboxConstants.MOUNTAINS, selectedMountains); return (mapping.findForward("success")); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | <%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <%-- html code, etc... --> <logic:iterate id="mountain" property="mountains" name="testForm"> <bean:write name="mountain"/><br/> </logic:iterate> <hr size=5 color="black"/> <%-- some more html code, etc... --> |
1 2 3 | <html:form action="/FormAction" name="testForm" type=" com.strutsrecipes.CheckboxTestForm"> |
1 2 3 | <logic:iterate id="mountain" property="mountains" name="testForm"> |
1 2 3 4 | <html:multibox property="selectedMountains"> <bean:write name="mountain"/> </html:multibox> <bean:write name="mountain"/><br/> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <logic:iterate id="mountainlb" property="mountainslb" name="testForm"> <bean:define id="mountainbean" name="mountainlb "type="org.apache.struts.util.LabelValueBean"/> <html:multibox property="selectedMountains"> <bean:write name="mountainbean" property="value"/> </html:multibox> <bean:write name="mountainbean" property="label"/><br/> </logic:iterate> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |