Struts2 six UI label form label and Data echo

Source: Internet
Author: User
UI Tags: tags used in JSP pages to echo data, which are defined by the framework to replace native tags. UI tags are: <s:textfield name= "xxx" ></s:textfield> <s:password name= "xxx" showpassword= "Trus" ></s:  password> <s:select name= "xxx" list= "xx" listkey=.  Listvalue=. Headervalue=. ><s/select> <s:checkboxlist list= "#pList" name= "pid" listkey= "pid" listvalue= "PName" ></s: Checkboxlist> need to echo the data to be placed in the valuestack, can be placed in the map stack, can also be placed in the object stack, there are two cases in the object stack: First, the data is encapsulated into a bean, the bean is placed in the object stack, and the other is to set the Action property, The Action property is in the object stack;
put data in 1.Action:
PublicclassUiactionextendsactionsupport{PrivateString username;PrivateString password; PublicString GetUserName () {returnUsername; }
PublicvoidSetusername (String username) { This. Username = Username; }
PublicString GetPassword () {returnpassword; }
PublicvoidSetPassword (String password) { This. Password = password;       }/** * 1. Echo the data in the form: The data is in the object stack and can be echoed directly based on the name data of the form element. * User name: <s:textfield name= "username" ></s:textfield><br/> Password: <s:password name= "pass Word "showpassword=" true "></s:password><br/> *@return*/ PublicString Showdatafromobjstack () {User user =NewUser ();           User.setpassword ("AAA");           User.setusername ("BBB"); Actioncontext. GetContext (). Getvaluestack (). push (user);return"User_objstack"; }/** * echo data from the map stack, S:textfield's Value property cannot be directly followed by OGNL expression, so you need to add%{OGNL expression} * User name: <s:textfiel D name= "username" value= "%{#user. Username}" ></s:textfield><br/> password: <s:password name= "PA ssWOrd "showpassword=" true "value="%{#user. Password} "></s:password><br/> *@return*       */ PublicString Showdatafrommap () {User user =NewUser ();           User.setpassword ("111");           User.setusername ("Zhangsan"); Actioncontext. GetContext (). Put ("user", user);return"User_map"; The properties in the/** * action are in the object stack and can be echoed directly using value on Echo: * User name: <s:textfield name= "username" ></s:text field><br/> Password: <s:password name= "Password" showpassword= "true" ></s:password><br/&       Gt *@return*/ PublicString Showdatafromactionproperty () { This. Username = "Lisi"; This. Password = "ASFD";return  "User_actionproperty"  ;      }            /**        * Use s:select tag to display drop-down selection box, must have List property;       * jsp: Select Province: <s:select Name= " pid" list= "#pList" listkey= "pid" listvalue= "PName" headerkey= "" headervalue= "please select Province" ></s:select > <br/>       * Translated code:       *  Select Province:                <select id= "UiAction_form_ Action_pid "Name=" pid >                     <option value= "" > Please select Province  </option>                     <option value= "1" > Beijing  </option>                     <option value= "2" > Shanghai  </option>                     <option value= "3" > Chongqing city  </option>                  </select>       *  @return*/ PublicString Putdatatoselect () {list<privice> pList =

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.