Down-to-earth, 1.1 points of accumulation. Understand the basics and principles. Introduction of three tag libraries:
Code:
- <% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "Bean" %>
- <% @ Taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
- <% @ 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:
- <% @ Page Language = "Java" Import = "Java. util. hashmap" pageencoding = "gb2312" %>
- <% @ Page import = "Po. Student" %>
- <% @ Taglib uri = "http://struts.apache.org/tags-bean" prefix = "Bean" %>
- <% @ Taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
- <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
- <HTML: HTML lang = "true">
- <Head>
- <Title> myjsp1.jsp </title>
- </Head>
- <Body>
- This is the first JSP interface! <Br>
- <! -- Traditional link practices -->
- <A href = "myjsp2.jsp"> link 1 </a> <br>
- <! -- The page uses the absolute path -->
- <HTML: link page = "/myjsp2.jsp"> link 2
- <! -- Href uses relative paths -->
- <HTML: link href = "myjsp2.jsp"> link 3
- <! -- To use forward, you need to modify the configuration file and re-deploy the configuration -->
- <HTML: link forward = "tootherpage"> Link 4
- <! -- Use Cases for passing parameters -->
- <HTML: link action = "XXX. Do"> connection 5 (some operations are also performed)
- <HR>
- <! -- Parameter transfer operation. -->
- <HTML: link page = "/myjsp2.jsp? Param = 007 "> parameter transfer (? Param = 007) the most traditional
- <Br>
- <%
- // 1
- Session. setattribute ("MSG", "007"); // use MSG
- // Compare the session to be found first
- Request. setattribute ("MSG", "<B> 007_request </B> ");
- Application. setattribute ("MSG", "007_applicatioin ");
- // 2
- Student Stu = new student ();
- Stu. setstuid ("<B> 071402119 </B> ");
- Session. setattribute ("Stu", Stu); // you need to upload the Object ID to the second interface.
- // 3 multiple parameters
- Hashmap Hm = new hashmap ();
- Hm. Put ("param1", "0001 ");
- Hm. Put ("param2", "002 ");
- Hm. Put ("param3", "003 ");
- Session. setattribute ("paramlist", HM );
- // Test whether the cookie label is read-only and not write-only.
- Response. addcookie (new cookie ("cname", "Biao"); // cookie uploaded to the second page
- %>
- <HTML: link page = "/myjsp2.jsp" paramid = "Param" paramname = "MSG"> parameter transfer (paramid = "Param" paramname = "MSG")
- <HTML: link page = "/myjsp2.jsp" paramid = "Param" paramname = "Stu" paramproperty = "stuid"> transfer student ID of a parameter
- <Br>
- <HTML: link page = "/myjsp2.jsp" name = "paramlist"> multiple parameters
- </Body>
- </Html: HTML>
<Myjsp2.jsp>
Code:
- <! -- Some code -->
- Ody>
- This is the second JSP interface! <Br>
- <! -- Request. getparameter ("Param") -->
- <! -- Equivalent to the following -->
- <% String STR = request. getparameter ("Param ");
- Out. Print (STR );
- // Minimize Java code in JSP pages
- %>
- <Br>
- <Bean: parameter id = "str2" name = "Param"/>
- <Bean: write name = "str2" filter = "false"/>
- // Display the attribute values in JavaBean
- <Bean: write name = "Stu" property = "stuid"/> <br>
- <Bean: Cookie id = "myselfname" name = "cname"/>
- <Bean: write name = "myselfname"/> <br>
- <Bean: write name = "myselfname" property = "value"/> <br>
- </Body>
The struts version is struts1.2. Simple tag learning without actiong and actionform. JavaBean: Specifies the attribute input of student.
Code:
- // Encapsulate a student profile
- Public class student {
- Private string stuid;
- Private string stuname;
- Private string stusex;
- Private string stubir;
- Private string stuadd;
- // Add a set for Traversal
- Private arraylist list;
- Public arraylist getlist (){
- Return list;
- }
- // The get and set functions are omitted.
- }