Bean taglib Learning

Source: Internet
Author: User
  1. <% @ Page contenttype = "text/html; charset = GBK" %>
  2. <% @ Page import = "Java. util. *" %>
  3. <% @ Page import = "edu. HUST. VO. *" %>
  4. <% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "Bean" %>
  5. <% @ Taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
  6. <% @ Taglib uri = "http://struts.apache.org/tags-logic" prefix = "logic" %>
  7. <% @ Taglib uri = "http://struts.apache.org/tags-tiles" prefix = "tiles" %>
  8. <! -- Bean: define learning -->
  9. <Bean: Define id = "str" value = "Hello Vivian"/>
  10. <H2> the content of the defined String object is: $ {STR} </H2> <HR>
  11. <! -- Bean: Size Learning -->
  12. <%
  13. Map map = new hashmap ();
  14. Map. Put ("1", "one ");
  15. Map. Put ("2", "two ");
  16. Map. Put ("3", "three ");
  17. Request. setattribute ("maplen", MAP );
  18. %>
  19. <Bean: Size id = "len" name = "maplen" Scope = "request"/>
  20. <H2> map length: $ {Len} </H2>
  21. <%
  22. Collection Col = new arraylist ();
  23. Col. Add ("one ");
  24. Col. Add ("two ");
  25. Request. setattribute ("Collen", col );
  26. %>
  27. <Bean: Size id = "len" name = "Collen" Scope = "request"/>
  28. <H2> collection length: $ {Len} </H2> <HR>
  29. <! -- Bean: Write Learning -->
  30. <! -- 1 common method -->
  31. <%
  32. /*
  33. User user = new user ();
  34. User. setuid ("u07 ");
  35. User. setname ("Forrest ");
  36. Request. setattribute ("user", user );
  37. */
  38. %>
  39. <! -- 2 improvement: Avoid Java code in JSP -->
  40. <! -- As long as it is a tag, it can be called in program development, because all the tags are basically operations on the four attribute ranges -->
  41. <JSP: usebean id = "user" Scope = "request" class = "edu. HUST. VO. User"/>
  42. <JSP: setproperty name = "user" property = "uid" value = "u07"/>
  43. <JSP: setproperty name = "user" property = "name" value = "Forrest"/>
  44. <! -- Output -->
  45. <H2> use el output: User. uid -- >$ {user. uid} & User. Name -- >$ {user. name} </H2>
  46. <H2> Use Bean: Write output: User. uid --> <Bean: write name = "user" property = "uid" Scope = "request"/> &&
  47. User. Name --> <Bean: write name = "user" property = "name" Scope = "request"/> </H2> <HR>
  48. <! -- Bean: Message Learning -->
  49. <! --
  50. Write the following code in applicationresources. properties:
  51. # Welcome
  52. Welcome = <H2>/u6b22/u8fce/u5149/u4e34 </H2>
  53. Then it is displayed in Bean: Message.
  54. -->
  55. <Bean: Message key = "welcome"/>
  56. <! --
  57. BEAN: the message tag provides the placeholder function, that is, it occupies one position in the output file, and the data of this position is dynamically filled in according to the tag.
  58. In applicationresources. properties, change the following code:
  59. # Welcome
  60. Welcome = <H2>/u6b22/u8fce {0}/u5149/u4e34 </H2>
  61. Then it is displayed in Bean: Message.
  62. -->
  63. <Bean: Message key = "welcome" arg0 = "Forrest"/> <HR>
  64. <! -- Bean: Message internationalization -->
  65. <! --
  66. All content is output through Bean: message, and then all languages form a *. properties file separately.
  67. Configure Chinese Characters in applicationresources. properties and American English in applicationresources_en_us.properties.
  68. The Display language varies according to the browser. (English is displayed by default in the browser. The browser automatically identifies the language and calls the corresponding language. properties file), because all the displayed content is in *. properties has been configured.
  69. Supplement: default browser language: tool-Internet option-language.
  70. -->

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.