Three tag libraries commonly used by struts (1)

Source: Internet
Author: User

Down-to-earth, 1.1 points of accumulation. Understand the basics and principles. Introduction of three tag libraries:

Code:
  1. <% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "Bean" %>
  2. <% @ Taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
  3. <% @ Taglib uri = "http://struts.apache.org/tags-logic" prefix = "logic" %>

Several Methods for connecting struts implementation: (Transfer from myjsp1.jsp to myjsp2.jsp)

<Myjsp1.jsp>

Code:
  1. <% @ Page Language = "Java" Import = "Java. util. hashmap" pageencoding = "gb2312" %>
  2. <% @ Page import = "Po. Student" %>
  3. <% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "Bean" %>
  4. <% @ Taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
  5. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  6. <HTML: HTML lang = "true">
  7. <Head>
  8. <Title> myjsp1.jsp </title>
  9. </Head>
  10. <Body>
  11. This is the first JSP interface! <Br>
  12. <! -- Traditional link practices -->
  13. <A href = "myjsp2.jsp"> link 1 </a> <br>
  14. <! -- The page uses the absolute path -->
  15. <HTML: link page = "/myjsp2.jsp"> link 2
  16. <! -- Href uses relative paths -->
  17. <HTML: link href = "myjsp2.jsp"> link 3
  18. <! -- To use forward, you need to modify the configuration file and re-deploy the configuration -->
  19. <HTML: link forward = "tootherpage"> Link 4
  20. <! -- Use Cases for passing parameters -->
  21. <HTML: link action = "XXX. Do"> connection 5 (some operations are also performed)
  22. <HR>
  23. <! -- Parameter transfer operation. -->
  24. <HTML: link page = "/myjsp2.jsp? Param = 007 "> parameter transfer (? Param = 007) the most traditional
  25. <Br>
  26. <%
  27. // 1
  28. Session. setattribute ("MSG", "007"); // use MSG
  29. // Compare the session to be found first
  30. Request. setattribute ("MSG", "<B> 007_request </B> ");
  31. Application. setattribute ("MSG", "007_applicatioin ");
  32. // 2
  33. Student Stu = new student ();
  34. Stu. setstuid ("<B> 071402119 </B> ");
  35. Session. setattribute ("Stu", Stu); // you need to upload the Object ID to the second interface.
  36. // 3 multiple parameters
  37. Hashmap Hm = new hashmap ();
  38. Hm. Put ("param1", "0001 ");
  39. Hm. Put ("param2", "002 ");
  40. Hm. Put ("param3", "003 ");
  41. Session. setattribute ("paramlist", HM );
  42. // Test whether the cookie label is read-only and not write-only.
  43. Response. addcookie (new cookie ("cname", "Biao"); // cookie uploaded to the second page
  44. %>
  45. <HTML: link page = "/myjsp2.jsp" paramid = "Param" paramname = "MSG"> parameter transfer (paramid = "Param" paramname = "MSG")
  46. <HTML: link page = "/myjsp2.jsp" paramid = "Param" paramname = "Stu" paramproperty = "stuid"> transfer student ID of a parameter
  47. <Br>
  48. <HTML: link page = "/myjsp2.jsp" name = "paramlist"> multiple parameters
  49. </Body>
  50. </Html: HTML>

<Myjsp2.jsp>

Code:
  1. <! -- Some code -->
  2. Ody>
  3. This is the second JSP interface! <Br>
  4. <! -- Request. getparameter ("Param") -->
  5. <! -- Equivalent to the following -->
  6. <% String STR = request. getparameter ("Param ");
  7. Out. Print (STR );
  8. // Minimize Java code in JSP pages
  9. %>
  10. <Br>
  11. <Bean: parameter id = "str2" name = "Param"/>
  12. <Bean: write name = "str2" filter = "false"/>
  13. // Display the attribute values in JavaBean
  14. <Bean: write name = "Stu" property = "stuid"/> <br>
  15. <Bean: Cookie id = "myselfname" name = "cname"/>
  16. <Bean: write name = "myselfname"/> <br>
  17. <Bean: write name = "myselfname" property = "value"/> <br>
  18. </Body>

The struts version is struts1.2. Simple tag learning without actiong and actionform. JavaBean: Specifies the attribute input of student.

Code:
  1. // Encapsulate a student profile
  2. Public class student {
  3. Private string stuid;
  4. Private string stuname;
  5. Private string stusex;
  6. Private string stubir;
  7. Private string stuadd;
  8. // Add a set for Traversal
  9. Private arraylist list;
  10. Public arraylist getlist (){
  11. Return list;
  12. }
  13. // The get and set functions are omitted.
  14. }

 

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.