struts2--Label

Source: Internet
Author: User

Generic Tags: property, set, Bean,include,param,debug

Control Tags: if elseif else, iterator, subset

UI Tags: theme, default simple XHTML, Css_xhtml, Ajax

Ajax Tags: supplemental

The difference between $#%

$ for i18n, struts configuration file

#取得actionContext的值

% will parse the original text attribute to OGNL,

INDEX.JSP:

<?xml version= "1.0" encoding= "GB18030"? ><%@ page language= "java" contenttype= "text/html; charset=gb18030 "    pageencoding=" GB18030 "%><%string ContextPath = Request.getcontextpath ();%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Tagsaction:

Package Com.bjsxt.struts2.tags;import Com.opensymphony.xwork2.actionsupport;public Class Tagsaction extends Actionsupport {private string Password;private string Username;public tagsaction () {}public string execute () { This.addfielderror ("Fielderror.test", "wrong!"); return SUCCESS;} Public String GetPassword () {return password;} Public String GetUserName () {return username;} public void SetPassword (String password) {this.password = password;} public void Setusername (String username) {this.username = username;}}

Struts.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts public    "-//apache software foundation//dtd struts Configuration 2.0//en"    "/http Struts.apache.org/dtds/struts-2.0.dtd "><struts>    <!--<constant Name=" Struts.enable.DynamicMethodInvocation "value=" false "/>-->    <constant name=" Struts.devmode "value=" True "/>    <!--<constant name=" struts.ognl.allowStaticMethodAccess "value=" true "></constant>- -    <constant name= "Struts.ui.theme" value= "simple"/><package name= "tags" extends= "Struts-default" >        <action name= "tags" class= "com.bjsxt.struts2.tags.TagsAction" >            <result>/tags.jsp</ result>        </action>    </package></struts>

TAGS.JSP:

<!--Property Label--
<body><ol>    <li>property: <s:property value= "username"/> </li><li>property Value is string: <s:property value= "' username '"/> </li><li>property set Default: <s:property value= "admin" default= "admin"/> </li><li>property set HTML: <s:property value= "' 
<!--set Label--variable name is too long to be used when changing names
<!--set has a scope, you can choose Page, Request,session, application,action, default is action and request-->
Do not write scope, say the default action and request, if you specify a different scope, you cannot use the action to take a value

<li> Set AdminName value (default to request and Actioncontext): <s:set var= "AdminName" value= "username"/></li> <li>set from Request: <s:property value= "#request. AdminName"/></li><li>set value from Actioncontext: <s:property value= "#adminName"/></li><li>set Set Range: Page<s:set name= "AdminPassword" value= " Password "scope=" page "/></li><li>set value from the corresponding range: <%=pagecontext.getattribute (" AdminPassword ")%> </li>
<li>set set Var, range is session: <s:set var= "AdminPassword" value= "password" scope= "session"/></li>< Li>set use # to value: <s:property value= "#adminPassword"/> </li> <!--do not get--><li>set from the corresponding range: <s: Property value= "#session. AdminPassword"/> </li>

 

<!--Bean Labels--
<li>bean defines the bean and uses Param to set the new property value: <s:bean name= "Com.bjsxt.struts2.tags.Dog" ><s:param name= "name" Value= "' pp '" ></s:param><s:property value= "name"/></s:bean></li><!-- The difference from the above is that there is a var below, which will be put into action, even if </s:bean> ends, Var already exists in Actioncontext, can also be taken out of the Actioncontext-
<li>bean View Debug Condition: <s:bean name= "Com.bjsxt.struts2.tags.Dog" var= "Mydog" > <s:param name= "name" value= "' Oudy '" ></s:param></s:bean> Fetch value: <s:property value= "#myDog. Name"/></li>
<!--include tags--try not to
<%@ include> static inclusions
<!include> Dynamic Inclusion

</li>

$,#,% differences:

$: For i18n and Struts configuration files

#: Get the value of Actioncontext

%: Resolves the original text attribute to OGNL, which is not a function of OGNL

<!--fielderror Label--
<li><s:fielderror fieldname= "Fielderror.test" theme= "simple" ></s:fielderror></li>
<!--ifelse Label--
Add &age=9&age=20 in the URL

<li>if ElseIf Else:
Age = <s:property value= "#parameters. age[0]"/> <br/>
<s:set var= "Age" value= "#parameters. age[0]"/>
<s:if test= "#age < 0" >wrong age!</s:if>
<s:elseif test= "#parameters. Age[0] <" >too young!</s:elseif>
<s:else>yeah!</s:else><br/>

<s:if test= "#parameters. AAA = = NULL" >null</s:if>
</li>

 

struts2--Label

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.