STRUTS2 basic Carding (II.)

Source: Internet
Author: User

This article mainly includes: setting struts2 matching extension, using wildcard character, value stack, declarative exception, and label.

Set the extension name:

By default, the. Action and no extension are processed. Can be set:

    <constant name= "struts.action.extension" value= "Action,do," ></constant>//to. Action,.do and no interception

Wildcard characters:

To simplify the configuration of the action, you can use a wildcard character, roughly as follows:

<action  name= "user_*" class= "jsky.action.ActionTestAction" method= "{1}" >      <result name= "Success" >/pages/{1}.jsp</result>      <result name= "error" >/pages/error2.jsp</result>      </ Action>
Rule: Precedence matches no wildcard, if multiple wildcard action, in order {1}{2} first, two strings

Value stack:

Stack of action, divided into object stacks and map stacks

    object stack:  access mode: object.propertyname; object[' PropertyName ']; object[" PropertyName "]
                  and nbsp objects can be referenced by a zero-based subscript. The top object in the Objectstack can be referenced by [0],  ,
          The object under it can be referenced using [1], starting from [0] objects to search for matching objects
                     name: <s:property value= "[0].name"/>
                      Pass: <s:property value= "Pass"/>

Map stack: The inside holds various Map:requestmap, Sessionmap, Applicationmap, Parametersmap, attr
Access method: #object. PropertyName; #object [' PropertyName ']; #object ["PropertyName"]
Session:<s:property value= "#session. SessionKey2"/>

Declarative Exceptions:

Specifies the page to go when the action is out of an exception, with the following approximate usage:

result specifies the page to go after the exception, exception refers to the type of exception that occurred

    <action  name= "Actiontest2" class= "jsky.action.ActionTestAction" method= "Log" >     < exception-mapping result= "error" exception= "Java.lang.ArithmeticException" ></exception-mapping>      <result name= "Success" >/pages/show2.jsp</result>      <result name= "error" >/pages/error2.jsp </result>     </action>

Label:

Struts2 with a special number of labels, here simply mention:

    • prperty label
pass:<s:property value= "Pass"/> Object
Session:<s:property value= "#session. SessionKey2"/><br>map

  • URL Tag
    <!--URL Label--  <s:url  value= "/testurl" var= "url" >   <s:param name= "TestID" value= "in" > </s:param>  </s:url>  ${url}   
  • Iterator label
    <s:iterator value= "#request. Users" >   ${name}:${pass}<br>   </s:iterator>

  • Forms tab:
    Self-bring typesetting, automatic echo and so on.
Finally, a registered function to solidify these tags, the effect is as follows:


The core code is as follows:

input.jsp

<body>  <s:form action= "Regis_save" >  <s:textfield name= "name" label= "Name" > </s: textfield>  <s:password name= "password" label= "password" ></s:password>  <s:radio name= " Gender "list=" #{' 1 ': ' Male ', ' 0 ': ' femal '} "label=" Gender "></s:radio>  <s:select name=" department " List= "#request. Department" listkey= "DepartmentID" listvalue= "Departmentname" label= "department" ></s:select >  <s:checkboxlist name= "role" list= "#request. Role" listkey= "Roleid" listvalue= "RoleName" label= "role" > </s:checkboxlist>  <s:submit value= "Submit" ></s:submit>  </s:form>  </body >
WELCOME.JSP:

<body>name: ${name}<br>pass:${password}<br>gender:${gender}<br>department: ${department} <br>role:${role}</body>
The main action:

Public String input () {request.put ("department", Dao.getdept ()), Request.put ("Role", Dao.getrole ()); return "Input";} Public String Save () {return "Success";} Private map<string, object> request; @Overridepublic void Setrequest (map<string, object> arg0) {//TODO auto-generated method Stub    this.request=arg0;}



STRUTS2 basic Carding (II.)

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.