<form>标签系列
使用<form>标签时必须遵循一些规则:
<html:form action=\"/login\" > 如果你有上述一个标签 ,那么你的 Struts 配置文件的元素中必须有一个如下显示为粗体的元素: <action-mappings> <action path=\"/login\" type=\"com.javapro.struts.LoginAction\" name=\"loginForm\" scope=\"request\" input=\"/login.jsp\"> <forward name=\"success\" path=\"/mainMenu.jsp\"/> </action> . . . </action-mappings> // 这就是说一个 form 标签是和 form bean 相关联的。 |
<body> <html:form action=\"/login\" focus=\"password\"> User Name: <html:text property=\"userName\"/> <br>Password: <html:text property=\"password\"/> <br><html:submit/> </html:form> </body> 代码解析后: <body> <form name=\"loginForm\" method=\"post\" action=\"/myStrutsApp/login.do\"> User Name: <input type=\"text\" name=\"userName\" value=\"\"> <br>Password: <input type=\"text\" name=\"password\" value=\"\"> <br><input type=\"submit\" value=\"Submit\"> </form> <script language=\"JavaScript\" type=\"text/javascript\"> <!-- if (document.forms[\"loginForm\"].elements[\"password\"].type != \"hidden\") document.forms[\"loginForm\"].elements[\"password\"].focus() // --> </script> </body> |
<html:password property=\"password\" redisplay=\"false\"/>
|
<html:select property=\"color\" size=\"3\"> <html:option value=\"r\">red</html:option> <html:option value= \"g\">green</html:option> <html:option value= \"b\">blue</html:option> </html:select> |
<html:link page="/html-link.do"> Linking with the page attribute. </html:link> |
<html:link href="/struts-exercise-taglib/html-link.do"> Using Href </html:link> |
<html:link href="http://otherserver/strutsTut/html-link.do"> Using Href </html:link> |
<html:link action="/html-link"> Using Action attribute </html:link> |
<html:link page="/htmllink.do?doubleProp=3.3&longProp=32"> Double and long via hard coded changes </html:link> |
<html:link page="/html-link.do" paramId="booleanProperty" paramName="testbean" paramProperty="nested.booleanProperty"> Boolean via paramId, paramName, and paramValue </html:link> |
<a href="/struts-exercise-taglib/html-link.do?booleanProperty=false"> Boolean via paramId, paramName, and paramValue </a> |
<% java.util.HashMap newValues = new java.util.HashMap(); newValues.put("floatProperty", new Float(444.0)); newValues.put("intProperty", new Integer(555)); newValues.put("stringArray", new String[] { "Value 1", "Value 2", "Value 3" }); pageContext.setAttribute("newValues", newValues); %> ... <html:link action="/html-link" name="newValues"> Float, int, and stringArray via name (Map) </html:link> |
<html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer"> <tr><td><%= pageContext.getAttribute("msg") %></td></tr> </html:messages> |