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 | <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <html:html locale="true"> <head> <title><bean:message key="testForm.title"/></title> <html:base/> </head> <body> <h3><bean:message key="testForm.heading"/></h3> <html:form action="/FormAction" name="testForm" type="com.strutsrecipes.RadioTestForm"> <h4><bean:message key="testForm.instruction"/></h4> <!-- gets the selected radio button --> <bean:define id="selectedRadio" property="selectedMountain" name="testForm"/> <!-- creates the radio button list --> <logic:iterate id="mountain" property="mountains" name="testForm"> <%-- you need this hack to get the value of the mountains to the page --%> <bean:define id="mountainValue"> <bean:write name="mountain"/> </bean:define> <html:radio property="selectedMountain" value="<%=mountainValue%>" styleId="<%=mountainValue%>"/> <bean:write name="mountain"/><br/> </logic:iterate><br/> <html:submit/> <html:reset/> <script type="text/javascript"> <!-- //Either of the following works. //Uncomment the one you wish to try and comment the other out. //var selectedRadio = document.getElementById("<bean:write //name="selectedRadio"/>"); var selectedRadio = document.forms["testForm"].elements["<bean:write name="selectedRadio"/>"]; selectedRadio.checked=true; --> </script> </html:form> </body> </html:html> |
1 2 3 4 5 6 7 | <%@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... --%> <bean:write name="mountain"/><br/> <hr size=5 color="black"/> <%-- some more html code, etc... --%> |
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 | ipackage com.strutsrecipes; 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; /** * The Action for the Radio Button test */ public final class RadioTestAction extends Action { // -------------------------- OTHER METHODS -------------------------- /** * The Action for the Radio Button test */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws ServletException, Exception { // Extract attributes needed String selectedMountains = ((RadioTestForm) form).getSelectedMountain(); System.out.println("htmlString RETURNED*********\n" + selectedMountains); //Save your htmlString in the session HttpSession session = request.getSession(); session.setAttribute(Constants.MOUNTAINS, selectedMountains); return (mapping.findForward("success")); } } |
1 | <bean:define id="selectedRadio" property="selectedMountains" name="testForm"/> |
1 2 | var selRadio = document.getElementById("<bean:write name="selectedRadio"/>"); selRadio.checked=true; |
1 2 3 | var selectedRadio = document.forms["testForm"].elements["<bean:writename="selectedRadio"/>"]; selectedRadio.checked=true; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <input type="radio" name="selectedMountain" value="Everest" id="Everest"/> Everest<br/> <input type="radio" name="selectedMountain" value="K2" id="K2"/> K2<br/> <input type="radio" name="selectedMountain" value="Kangchenjunga" checked="checked" id="Kangchenjunga"/> Kangchenjunga<br/> <input type="radio" name="selectedMountain" value="Lhotse" id="Lhotse"/> Lhotse<br/> <input type="radio" name="selectedMountain" value="Makalu" id="Makalu"/> Makalu<br/> <input type="radio" name="selectedMountain" value="Cho Oyu" id="Cho Oyu"/> Cho Oyu<br/> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |