Use of struts2.0 labels

Source: Internet
Author: User

1: The property value in the output action is displayed on the jsp page with: <s: property value = "property name"/> 2: to automatically add sequence numbers on the page, use the index attribute eg: <s: iterator value = "# request. inOutAccountList "id =" data "status =" listStat "> // inOoutAccountList must have the getting and setting methods <s: property value =" # listStat. index + 1 "/> <! -Output the index of the current iteration element <s: property value = "# listStat. index"/> <! -Output several elements of the current iteration <s: property value = "# listStat. count"/> <! -Returns whether the index of the current iteration element is an odd number. <s: property value = "# listStat. odd"/> <! -Returns whether the index of the current iteration element is an even number. <s: property value = "# listStat. event"/> <! -Returns whether the current element is the first element <s: property value = "# listStat. first"/> <! -Returns whether the current element is the last element <s: property value = "# listStat. last "/> </s: iterator> 3: Obtain the request and session Object method in the action class. Map session = ActionContext. getContext (). getSession (); HttpServletRequest request = ServletActionContext. getRequest (); method for setting their values: session. put ("operation", "add"); request. setAttribute ("name", name); obtain their values on the page: <s: property value = "# session. operation "/> <s: property value =" # session ['operation'] "/>$ {sessi OnScope. TEST }==$ {session. TEST} <s: if test = "# session. operation = 'add' "> <s: if test =" # session ['operation'] = 'add' "> <s: if test = "# session ['operation'] = null"> <s: property value = "# request. name "/>$ {requestScope. name }== {request. name} 4: the style of the odd and even rows on the page is different: <tr class = "<s: if test = '# listStat. odd = true '> tableStyle-tr1 </s: if> <s: else> tableStyle-tr2 </s: else> "> 5: How to use single-digit and check boxes 1 ): you can set the default selected value. Pay attention to the setting of the list value. In this way Make the key and value different. This method is commonly used (checkboxlist or radio) <s: radio name = "uncarInsPolicy. policyStateCode "list =" # {'5': 'pass', '2 ': 'do not pass'} "listKey =" key "listValue =" value "value = '5'/> 2 ): here the key and value values are the same (checkboxlist or radio) <s: checkboxlist list = "{'red', 'blue ', 'green'} "name =" favoriteColor "/> 6: the tag in struts2 generates a string similar to <tr> <td> </tr> (what tag is generated, you can check the source code of the generated page.) If you do not limit the generation of the redundant code, the page will become uncontrollable. Therefore, we generally do not want it to generate redundant code. Body Setting method if, in struts. configure <constant name = "struts. ui. theme "value =" simple "/> with this sentence, you can also set the theme attribute of the tag to" simple "on the page to cancel its default table layout, but it is best: you can customize a theme and set it to apply it to the entire site by default. In this way, you can get a unified site style 7: Date formatting method on the jsp page <s: date name = "unCarInsModificationInfo. createTime "format =" yyyy-MM-dd "nice =" false "/> to format the date in the format of yyyy-MM-dd 8: by default, when a request action occurs, Struts Runtime is based on struts. the Action ing set (Mapping) in xml, instantiate the class corresponding to the action, and call its execute method. Of course, we can use the following two methods to change this default call 1) in classes/sturts. create an Action in xml and specify the method it calls. For example, you want to call public String aliasAction () {message = "Custom action call method"; return SUCCESS ;} then in classes/sturts. add the following code to xml: <action name = "AliasHelloWorld" class = "tutorial. helloWorld "method =" aliasAction "> <result>/HelloWorld. jsp </result> </action> can call this method using the action name. 2) when accessing the Action, add "! Xxx "(xxx is the method name ). 9: Struts 2.0 has two configuration files, struts. xml and struts. properties are placed in the WEB-INF/classes. Struts. xml is used for application-related configuration struts. properties is used for Struts 2.0 Runtime configuration 10: Obtain the physical path (absolute path) of a folder on the web in the action class filePath = ServletActionContext. getServletContext (). getRealPath ("/upLoadFiles") 11) in struts. set <result name = "list" type = "redirect-action"> sysmanage/UserBaseInfoAction! FindUserBaseInfo. action </result> 2) return findList () by directly calling this method when returning in action; 12: Set the default method in checkboxlist <s: checkboxlist name = "skills1" = "Skills 1" list = "{'java ','.. Net ', 'ror', 'php'} "value =" {'java ','. net '} "/> <s: checkboxlist name =" skills2 "label =" Skills 2 "list =" # {1: 'java', 2 :'. net ', 3: 'ror', 4: 'php'} "listKey =" key "listValue =" value "value =" {1, 2, 3} "/> 13: Level-2 connection drop-down box <s: set name =" foobar "value = "# {'Java': {'spring', 'hibernate ', 'struts 2 '},'. net': {'linq ', 'asp. NET 2.0 '}, 'database': {'oracle', 'SQL Server', 'db2', 'mysql'} "/> <s: doubleselect list = "# foobar. keySet () "doubleName =" technology "doubleList =" # foobar [top] "label =" Technology "/> 14: retrieve the attribute values in the list object on the page <s: if test = "list! = Null & list. size ()> 0 "> <s: iterator value =" list "status =" stat "> <! -If select id, name, title --> <s: property value = "list [# stat. index] [0]"/> <! -If multiple objects are stored in the list, such as left join Role left join Group --> <s: property value = "list [# stat. index] [0]. title "/> <s: property value =" list [# stat. index] [1]. title "/> <! -If it is stored as Map --> <s: iterator value = "mapUsers. keySet () "id =" id "> <s: property value =" # id "/> <s: iterator value =" mapUsers. get (# id) "> <s: property value =" nickname "/> | <s: property value =" UName "/> </s: iterator> </s: iterator> <! -Determine if it is an odd number --> <s: if test = "stat. odd = true"> </s: if> <! -Determine if it is the first data --> <s: if test = "# stat. index = 0"> <s: if test = "# stat. first"> <! -Determine whether the attribute is null --> <s: if test = "list [# stat. index] [0]. title = null"> <! -Declare the property value as a variable --> <s: set name = "title" value = "list [# stat. index] [0]. title "> </s: set> <! -Determine the attribute value --> <s: if test = "list [# stat. index] [0]. title = 4 "> <s: if test =" list [# stat. index] [0]. title = 'admin' "> <s: if test =" # title = 4 "> <s: if test =" list [# stat. index] [0]. title. length ()> 15 "> <s: property value =" list [# stat. index] [0]. title. substring (0, 15) "/>... </s: if> 14: Obtain the select value <s: select list = "listDept" name = "selectDept" listKey = "val" listValue = "prntext" disabled = "true" value = "deptSelected"/> www. 2ct O.com <s: hidden name = "selectDept" value = "% {deptSelected}"/> 15: The first attribute specifies the start value of the loop for int type data in a loop, last indicates the cyclic termination value. For other related attributes, you can view org. apache. struts2.util. counter class source code. Enter the current value of the loop in the following iterator: current <s: bean name = "org. apache. struts2.util. counter "> <s: param name =" first "value =" 1 "/> <s: param name =" last "value =" pages "/> <! -Pages page is the action property. <s: iterator> <s: if test = "current-1 = page"> <font color = "red"> <s: property/> </font> </s: if> <s: else> [<s: property/>] </s: else> </s: iterator> </s: bean> 16: output the value in the International File <s: text name = "key" >$ {getText ["key"]} 17: output the message <s: actionmessage/> 18: Error in the output Action <s: actionerror/>

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.