JSP implementation custom form label _jsp programming for automatically generating form label HTML code

Source: Internet
Author: User
Tags java web

This example describes a custom form label that the JSP implementation uses to automatically generate form label HTML code. Share to everyone for your reference. Specifically as follows:

This is your own write a simple JSP form label, used to automatically generate Checkbox,select,radio tags, incoming menu collection to generate HTML code, automatically select the specified value for the Java Web Project JSP page.

1. servlet Section Code:

map<string, string> map = new hashmap<string, string> ();
Map.put ("2", "option Two");
Map.put ("3", "option Three");
Map.put ("4", "option Four");
Map.put ("5", "option Five");
Map.put ("6", "option Six");
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 one </option>
  <g:option value=" 1 "> This selected </g:option>
  <!--items must be set or map-->
  <g:options items= "${map}"/>
</g:select>
<!--CheckValue supports EL, can be a collection or string, Specifies which automatically generated checkbox is selected-->
<g:checkboxs checkvalue= "${list}" items= "${map}" name= "checkbox"/>
<! --CheckValue can only be strings, support El-->
<g:radios items= "${map}" name= "Radio" checkvalue= "3"/>

3. Generated HTML code:

<select> <option value= "0" > Option one </option> <option value= "1" selected= "selected" > This was selected </ Option> <!--items must be a collection or map--> <option value= "3" > option three </option> <option value= "2" > Option two </ Option> <option value= "6" > option six </option> <option value= "5" > option five </option> <option value= "4 "> Option four </option> </select> <!--checkvalue support El, can be a collection or a string, specify automatically generated checkbox which is selected--> <div class= "Checkbox-div" ><input type= "checkbox" id= "CheckBox1" name= "checkbox" value= "3"/><label for= "CheckBox1" > Option three </label></div><div class= "Checkbox-div" ><input type= checkbox "id=" CheckBox2 "Name=" CheckBox "Value=" 2 "/><label for=" checkbox2 "> Option two </label></div><div class=" Checkbox-div " ><input type= "checkbox" id= "Checkbox3" name= "checkbox" value= "6" checked= "checked"/><label for= " Checkbox3 "> option six </label></div><div class=" Checkbox-div "><input type= "checkbox" id= "checkbox4" name= "checkbox" value= "5" checked= "checked"/><label for= "checkbox4" > Option Five < /label></div><div class= "Checkbox-div" ><input type= "checkbox" id= "checkbox5" name= "checkbox" Value= "4" checked= "checked"/><label for= "CHECKBOX5" > Options four </label></div> <!-- CheckValue can only be strings that support El--> <div class= "Radio-div" ><input type= "Radio" id= "Radio1" name= "Radio" value= "3" Checked= "Checked"/><label for= "radio1" > Option three </label></div><div class= "Radio-div" >< Input type= "Radio" id= "Radio2" name= "Radio" value= "2"/><label for= "Radio2" > Option two </label></div> <div class= "Radio-div" ><input type= "Radio" id= "Radio3" name= "Radio" value= "6"/><label for= "Radio3" > option six </label></div><div class= "Radio-div" ><input type= "Radio" id= "Radio4" name= "Radio" value = "5"/><label for= "Radio4" > option five </label></div><div class= "Radio-div" ><inpuT type= "Radio" id= "Radio5" name= "Radio" value= "4"/><label for= "Radio5" > option four </label></div>

 

I hope this article will help you with your JSP programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.