JSP implementation is used to automatically generate form tags. html code custom form tags are automatically generated by jsp.
This example describes how to use JSP to automatically generate custom form tags for form tags html code. Share it with you for your reference. The details are as follows:
This is a simple JSP form tag written by myself. It is used to automatically generate tags such as checkbox, select, and radio, input the menu set to generate html code, and automatically select the specified value, jsp pages for java web projects.
1. Some Servlet code:
Map <String, String> map = new HashMap <String, String> (); map. put ("2", "option 2"); map. put ("3", "option 3"); map. put ("4", "option 4"); map. put ("5", "option 5"); map. put ("6", "Option 6"); req. setAttribute ("map", map); List <String> list = new ArrayList <String> (); list. add ("4"); list. add ("5"); list. add ("6"); req. setAttribute ("list", list );
2. JSP code:
<% @ Taglib prefix = "g" uri = "http://www.golpesoft.com" %> <g: select value = "1"> <option value = "0"> option 1 </option> <g: option value = "1"> selected </g: option> <! -- Items must be a set or map --> <g: options items = "$ {map}"/> </g: select> <! -- CheckValue supports el, which can be a set or string to specify which checkboxes are automatically generated --> <g: checkboxs checkValue = "$ {list}" items = "$ {map}" name = "checkbox"/> <! -- CheckValue can only be a string and supports el --> <g: radios items = "$ {map}" name = "radio" checkValue = "3"/>
3. generated html code:
<Select> <option value = "0"> option 1 </option> <option value = "1" selected = "selected"> selected </option> <! -- Items must be a set or map --> <option value = "3"> option 3 </option> <option value = "2"> option 2 </option> <option value = "6"> option 6 </option> <option value = "5"> option 5 </option> <option value = "4"> option 4 </option> </select> <! -- CheckValue supports el, which can be a set or string, specify which checkboxes are automatically generated --> <div class = "checkbox-div"> <input type = "checkbox" id = "checkbox1" name = "checkbox" value =" 3 "/> <label for =" checkbox1 "> Option 3 </label> </div> <div class =" checkbox-div "> <input type =" checkbox "id = "checkbox2" name = "checkbox" value = "2"/> <label for = "checkbox2"> Option 2 </label> </div> <div class = "checkbox "-div "> <input type =" checkbox "id =" checkbox3 "name =" checkbox "value = "6" checked = "checked"/> <label for = "checkbox3"> Option 6 </label> </div> <div class = "checkbox-div"> <input type = "checkbox" id = "checkbox4" name = "checkbox" value = "5" checked = "checked"/> <label for = "checkbox4"> Option 5 </ label> </div> <div class = "checkbox-div"> <input type = "checkbox" id = "checkbox5" name = "checkbox" value = "4" checked = "checked"/> <label for = "checkbox5"> Option 4 </label> </div> <! -- CheckValue can only be a string, support el --> <div class = "radio-div"> <input type = "radio" id = "radio1" name = "radio" value = "3" checked = "checked ""/> <label for =" radio1 "> Option 3 </label> </div> <div class =" radio-div "> <input type =" radio "id = "radio2" name = "radio" value = "2"/> <label for = "radio2"> Option 2 </label> </div> <div class = "radio- div "> <input type =" radio "id =" radio3 "name =" radio "value =" 6 "/> <label for =" radio3 "> Option 6 </label> </div> <div class = "radio-div"> <input type = "radio" id = "radio4" name = "radio" value = "5"/> <label for = "radio4"> Option 5 </label> </div> <div class = "radio-div"> <input type = "radio" id = "radio5" name = "radio" value = "4"/> <label for = "radio5"> Option 4 </label> </div>
I hope this article will help you with JSP program design.