Java Technical Summary

Source: Internet
Author: User

Related Articles:
JBoss + Jetty solution to Chinese problems
Use ValueStack or ActionContext?
Request. getRequestURI problems when using struts

Recommendation circle: GT-Grid
For more information, see <s: property value = "variable name"/>.

2: automatically add the sequence number on the page. Use the index attribute eg of statuts of iterator:

<S: iterator value = "# request. inOutAccountList" id = "data" status = "listStat">

<S: property value = "# listStat. index + 1"/>

</S: iterator>

3: Methods for obtaining request and session objects in the action class

Map session = ActionContext. getContext (). getSession ();
HttpServletRequest request = ServletActionContext. getRequest ();

How to set their values

Session. put ("operation", "add ");
Request. setAttribute ("name", name );

Obtain their values on the page:

<S: property value = "# session. operation"/>
<S: property value = "# request. name"/>

4: the style of the odd and even rows on the page is different:

<Tr class = "<s: if test = '# listStat. odd = true '> tableStyle-tr1 </s: if> <s: else> tableStyle-tr2 </s: else> ">

5: How to use single-digit and check boxes

1): You can set the default selected value. Pay attention to the setting of the value of list. In this way, the key and value are different. This method is commonly used (checkboxlist or radio)

<S: radio name = "uncarInsPolicy. policyStateCode"
List = "# {'5': 'pass', '2': 'Password '}"
ListKey = "key"
ListValue = "value"
Value = '5'
/>

2): the key and value here are the same (checkboxlist or radio)

<S: checkboxlist
List = "{'red', 'Blue ', 'green '}"
Name = "favoriteColor"/>

6: The tag in struts2 generates a string similar to <tr> <td> </tr> (what tag is generated, you can view the source code of the generated page.) If you do not limit the generation of unnecessary code, the page becomes uncontrollable. Therefore, we generally do not want it to generate unnecessary code, the specific setting method is as follows. unified configuration in xml
<Constant name = "struts. ui. theme" value = "simple"/> Add this sentence.
You can also set the theme attribute of the tag to "simple" on the page to cancel its default table layout.
But it is best to: Customize a theme and set it as the default application to the entire site, so that you can get a unified site Style

7: how to format a date on a jsp page

<S: date name = "unCarInsModificationInfo. createTime "format =" yyyy-MM-dd "nice =" false "/> to format the date as yyyy-MM-dd

8: by default, when a request action occurs, the Struts Runtime is based on struts. the Action ing set (Mapping) in xml, instantiate the class corresponding to the action, and call its execute method. Of course, we can change this default call using the following two methods:

1) create an Action in classes/sturts. xml and specify the method to call.
For example, if you want to call

Public String aliasAction (){
Message = "Custom Action call method ";
Return SUCCESS;
}
Add the following code to classes/sturts. xml:
<Action name = "AliasHelloWorld" class = "tutorial. HelloWorld" method = "aliasAction">
<Result>/HelloWorld. jsp </result>
</Action>
You can call this method using the action name.

2) (more common)

When accessing the Action, add "! Xxx "(xxx is the method name ).

9: Struts 2.0 has two configuration files, struts. xml and struts. properties are placed in the WEB-INF/classes.
Struts. xml is used for application-related configuration.
Struts. properties is used for the Runtime configuration of Struts 2.0.

10: Obtain the physical path (absolute path) of a folder on the web in the action class
FilePath = ServletActionContext. getServletContext (). getRealPath ("/upLoadFiles ")

11: to return a page that is not a direct JSP page, you must first read the corresponding data by returning the method in the action and then return to the jsp page. There are two methods:

1) set this in struts. xml.

<Result name = "list" type = "redirect-action"> sysmanage/UserBaseInfoAction! FindUserBaseInfo. action </result>

2) You can directly call this method when returning in action.

Return findList ();

12: Set the default value in checkboxlist

<S: checkboxlist name = "skills1"
= "Skills 1"
List = "{'java', '. net', 'error', 'php '}"
Value = "{'java', '. net'}"/>
<S: checkboxlist name = "skills2"
Label = "Skills 2"
List = "# {1: 'java', 2: '. net', 3: 'ror', 4: 'php '}"
ListKey = "key"
ListValue = "value"
Value = "{1, 2, 3}"/>

13: Level-2 connection drop-down list

<S: set name = "foobar"
Value = "# {'java': {'spring ', 'hibernate', 'struts 2 '},'. net': {'linq ', 'asp. NET 2.0 '}, 'database': {'oracle', 'SQL Server', 'db2', 'mysql'} "/>
<S: doubleselect list = "# foobar. keySet ()"
DoubleName = "technology"
DoubleList = "# foobar [top]"
Label = "Technology"/>

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.