Class hour 28

  • Struts 2 Explanation of common labels

property label

property The tag is used to output the specified value :
<s:set name="name" value="'kk'" />
<s:property value="#name"/>
default: Optional attribute , If the output property value is null, The value specified by the property is displayed
escape: Optional attribute , Specifies whether to format HTML Code .
value: Optional attribute , Specify the attribute value to output , If the property is not specified , Default output ValueStack Value at top of stack .
id: Optional attribute , Specifies the identity of the element

iterator label

iterator Tags are used to iterate over sets , The set here contains List、Set And an array .
<s:set name="list" value="{'zhangming','xiaoi','liming'}" />
<s:iterator value="#list" status="st"> <!-- s:iterator The tag will put the object of the current iteration at the top of the value stack -->
<font color=<s:if test="#st.odd">red</s:if><s:else>blue</s:else>>
<s:property /></font><br>
</s:iterator>
value: Optional attribute , Specify the set to be iterated , If the property is not set , Then use ValueStack The collection at the top of the stack .
id: Optional attribute , Specifies the... Of the elements in the collection id.
status: Optional attribute , This property specifies... At iteration time IteratorStatus example . This example includes the following methods :
int getCount(), Returns several elements of the current iteration .
int getIndex(), Returns the index of the current iteration element .
boolean isEven(), Returns whether the index of the current iterated element is even
boolean isOdd(), Returns whether the index of the current iterated element is odd
boolean isFirst(), Returns whether the current iterated element is the first one .
boolean isLast(), Returns whether the current iterated element is the last one .

 if/elseif/else label

<s:set name="age" value="21" />
<s:if test="#age==23">
23
</s:if>
<s:elseif test="#age==21">
21
</s:elseif>
<s:else>
It doesn't matter
</s:else>
<s:set name="age" value="22" scope="request"/>
<s:if test="#request.age==23">

url label ( The default is hyperlinks <a href="">...</a>)( benefits : No context path and suffix )

<s:url action="helloworld_add" namespace="/test"><s:param name="personid" value="33"/></s:url>
<s:url action="helloworld_add" namespace="/test"><s:param name="personid" value="#request.age"/></s:url> <!-- Acquiescence acceptance OGNL expression -->

Generate a path similar to the following :
/struts/test/helloworld_add.action?personid=23
The red part is the content path .

When the attribute value of a label is treated as a string type (struts2 Label property values accept... By default OGNL expression ), “%” The purpose of symbols is to calculate OGNL Value of expression .

<s:set name="myurl" value="'http://www.foshanshop.net'"/>
<s:url value="#myurl" /><br>
<s:url value="%{#myurl}" />

Output results :
#myurl
http://www.foshanshop.net

Form labels _checkboxlist Check box

If the set is list

<!-- struts2 Automatic generation <tr><td> Such as tag ( The theme ), If you don't need theme function , Add constants to the configuration file 
<constant name="struts.ui.theme" value="simple" /> Represents the default view theme
-->
<s:checkboxlist name="list" list="{'Java','.Net','RoR','PHP'}" value="{'Java','.Net'}"/>
Generated as follows html Code :
<input type="checkbox" name="list" value="Java" checked="checked"/><label>Java</label>
<input type="checkbox" name="list" value=".Net" checked="checked"/><label>.Net</label>
<input type="checkbox" name="list" value="RoR"/><label>RoR</label>
<input type="checkbox" name="list" value="PHP"/><label>PHP</label>

If the set is MAP

<s:checkboxlist name="map" list="#{1:' Yoga products ',2:' Outdoor products ',3:' ball game ',4:' Bicycle '}" listKey="key" listValue="value" value="{1,2,3}"/>
<!--listKey Access the top of the stack object key Property as a check box vlue Value ,listValue As lable Value -->
Generated as follows html Code :
<input type="checkbox" name="map" value="1" checked="checked"/><label> Yoga products </label>
<input type="checkbox" name="map" value="2" checked="checked"/><label> Outdoor products </label>
<input type="checkbox" name="map" value="3" checked="checked"/><label> ball game </label>
<input type="checkbox" name="map" value="4"/><label> Bicycle </label>

If what's in the collection is javabean

<%
Person person1 = new Person(1," first ");
Person person2 = new Person(2," the second ");
List<Person> list = new ArrayList<Person>();
list.add(person1);
list.add(person2);
request.setAttribute("persons",list);
%>
<s:checkboxlist name="beans" list="#request.persons" listKey="personid" listValue="name"/>
<!--list="#request.persons" During iteration, the current iteration element is placed at the top of the stack -->
Personid and name by Person Properties of Generated as follows html Code :
<input type="checkbox" name=“beans" value="1"/><label> first </label>
<input type="checkbox" name=“beans" value="2"/><label> the second </label>

Form labels _radio Radio buttons

The use of the label and checkboxlist The check boxes are the same .
If what's in the collection is javabean(personid and name by Person Properties of )

< s:radio name="beans" list="#request.persons" listKey="personid" listValue="name"/>
Generated as follows html Code :
<input type="radio" name="beans" id="beans1" value="1"/><label> first </label>
<input type="radio" name="beans" id="beans2" value="2"/><label> the second </label>

If the set is MAP

<s:radio name="map" list="#{1:' Yoga products ',2:' Outdoor products ',3:' ball game ',4:' Bicycle '}" listKey="key" listValue="value“ value="1"/>
Generated as follows html Code :
<input type="radio" name="map" id="map1" value="1"/><label for="map1"> Yoga products </label>
<input type="radio" name="map" id="map2" value="2"/><label for="map2"> Outdoor products </label>
<input type="radio" name="map" id="map3" value="3"/><label for="map3"> ball game </label>
<input type="radio" name="map" id="map4" value="4"/><label for="map4"> Bicycle </label>

If the set is list

<s:radio name="list" list="{'Java','.Net'}" value="'Java'"/>
Generated as follows html Code :
<input type="radio" name="list" checked="checked" value="Java"/><label>Java</label>
<input type="radio" name="list" value=".Net"/><label>.Net</label>

  Form labels _select Drop down the selection box

<s:select name="list" list="{'Java','.Net'}" value="'Java'"/>
Generated as follows html Code :
<select name="list" id="list">
<option value="Java" selected="selected">Java</option>
<option value=".Net">.Net</option>
</select> <s:select name="beans" list="#request.persons" listKey="personid" listValue="name"/>
Generated as follows html Code :
<select name="beans" id="beans">
<option value="1"> first </option>
<option value="2"> the second </option>
</select> <s:select name="map" list="#{1:' Yoga products ',2:' Outdoor products ',3:' ball game ',4:' Bicycle '}" listKey="key" listValue="value" value="1"/>
Generated as follows html Code :
<select name="map" id="map">
<option value="1" selected="selected"> Yoga products </option>
<option value="2"> Outdoor products </option>
<option value="3"> ball game </option>
<option value="4"> Bicycle </option>
</select>

  
Class hour 30

  • Use tags to prevent duplicate submission of forms

<s:token /> Tags prevent duplicate submissions , Usage is as follows :
First step : Add... To the form <s:token />

<s:form action="list_execute" namespace="/test" method="post">
full name :<s:textfield name="name"></s:textfield><s:token></s:token>
<input type="submit" value=" Submit "/>
</s:form>

The second step :

<action name="list_*" class="tutorial.Person" method="{1}">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="token"></interceptor-ref>
<result name="invalid.token">/index.jsp</result>
<result name="success">/page.jsp</result>
</action>

The above configuration adds “token” Interceptors and “invalid.token” result , because “token” The interceptor is at the beginning of the conversation token With the request of token When not in agreement , Will return directly to “invalid.token” result . After submission , Server side token( Store in session On ) Will change , Submit again , Client and server token inequality

struts2 Video learning notes 29-30(Struts 2 Commonly used labels , Prevent forms from being submitted repeatedly ) More articles about

  1. JavaWeb Learning summary ( 11、 ... and ):Session solve form Form resubmission

    In normal development , If the network speed is slow , After the user submits the form , I found that the server didn't respond for half a day , Then users may think that they did not submit the form , And then click the submit button to submit the form again , We must prevent the form from being submitted repeatedly in the development . One . The form repeats ...

  2. struts2 Video learning notes 03-06(Struts 2 There is no problem with the configuration file ,Action Default values for each item in the configuration , Various forwarding types )

    Class hour 3 solve Struts 2 There is no problem with the configuration file (eclipse):window→preference→XML→XML Catlog

  3. Silicon Valley STRUTS2 Video learning notes

    I've been studying for the last month STRUTS2, Learning is still Silicon Valley teacher Tong Gang's video , Because I like teacher Tong Gang's voice very much , And he's very detailed , I take a lot of notes , Basically according to his video complete knock once code , Let's sort out what we have learned , Finally, the project ...

  4. [ original ]java WEB Learning notes 73:Struts2 Way of learning -- strut2 Prevent duplicate submission of forms in

    The purpose of this blog :① Summarize your learning process , It's like learning notes ② Share your experience with you , Learn from each other , Communicate with each other , Not for commercial use There are bound to be problems with the content , Welcome to correct , communication , discuss , You can leave a message , You can also contact through the following ways . I love internet technology ...

  5. I'm confused and forced to study Struts Data verification and data echo , Model driven , Application to prevent form duplicate submission .

    1:Struts2 Form data verification : (1) Front desk check , Also known as client verification , Mainly through Javascript Program to verify the data . (2) Background verification , Also known as server validation , This refers to the use of Struts2 adopt xm ...

  6. Struts2 note —— utilize token Prevent forms from being submitted repeatedly

    In some projects, users are often asked to submit forms , When the user clicks the submit button , If the browser refreshes again , This will cause the form to be submitted repeatedly , If the submitted content is uploaded to the server and requested to be saved in the database , Duplicate forms can cause errors , Then jump to the error screen , This is one ...

  7. HTML+CSS Learning notes (5)- Interact with the viewer , Form labels

    HTML+CSS Learning notes (5)- Interact with the viewer , Form labels 1. Use form tags , Interact with users How the website interacts with users ? The answer is to use HTML Forms (form). The form can send the data entered by the browser to the server , Service like this ...

  8. Struts2 Based on learning ( 8、 ... and )&mdash;Struts2 Prevent forms from being submitted repeatedly

    One . reason      The repeated submission of forms by users will cause serious consequences in some cases . for example , When using credit cards to pay online , If the response speed of the server is too fast slow , Users may click the submit button many times , And this may cause the amount on that credit card to be cancelled ...

  9. java struts2 Introduction learning -- Prevent forms from being submitted repeatedly .OGNL Language learning

    One . Knowledge review The core idea of preventing duplicate submission of forms : Client side and server side and write a token, Compare the two token The value of is the same , Non duplicate submission ; Different , It's a duplicate submission . 1.getSession Three ways to compare : request. ...

Random recommendation

  1. B-Tree Study

    Introduction to algorithms The first 18 Chapter B The difference between the structure of trees and other trees is  B A number is a multi tree, not a binary tree And the bifurcation factor is very large, generally used in the database For the need of hard disk IO And use You can lower the disk IOB One node of the tree is the page of the disk , Not data ...

  2. nginx Port occupied solution

    killall -9 nginx or service nginx restart( Restart )

  3. Complete example (C# Socket)

    Problem description :          Now create a C# Socket example , When the client is disconnected, the server can immediately output the disconnected client information The server is disconnected , The client can detect the status of the server immediately Problem solving : Server-side code : Client code : above ...

  4. Git Remote branch view and related issues

    command :git ls-remote -t perhaps git ls-remote --tag The operation results are as follows : 0975ebc0f9a6b42ecbe066a50a26a678a0753b4d refs/tag ...

  5. QEMU, a Fast and Portable Dynamic Translator-Fabrice Bellard- translate

    Abstract We present the internals of QEMU, a fast machine emulator using an original portable dynami ...

  6. [DIV+CSS] set the screen capture Part 1 (div Interception screen )

    Use the following code to get the screen . use DIV Add CSS To control . Use mousemove To get moving DIV The change of , The renderings are as follows : Use 5 individual DIV To make up the first part of achieving the purpose of the screenshot , Now it's just the first part of the choice . HT ...

  7. The problem of monkeys eating peaches (Java Recursive implementation )

    The problem of monkeys eating peaches : The monkey picked some peaches on the first day , Half eaten immediately , Not yet , Another one , The next morning I ate half of the rest of the peaches , Another one . After that, I ate half and one of the rest of the day before every morning . To the first 10 When I want to eat again in the morning , See, there's nothing left ...

  8. Python Realize image information hiding

    Python Realize image information hiding When I studied cryptography before, the teacher mentioned 『 Information hiding 』, Now try the image method . Thought is : Hide information in RGB In the tunnel B passageway , And then parity can be used to recover principle Extract text image information from source image ...

  9. DOORS The type of reference

    DOORS The reference types of include :Project: Project reference Folder: Folder references Item: Items within a project or folder ( project . Folder . modular )Module: Open the reference to the module Object: References to objects  ...

  10. easyui Tree dynamic loading reference

    This article is a copy of , Thanks to the original author Friendship connection :http://www.jb51.net/article/28771.htm var treeTitle = ' Selection list '; var treeUrl = '../ ...