Java Technology Summary

Source: Internet
Author: User

Related articles:
The solution of Jboss+jetty Chinese problem
Using Valuestack or Actioncontext?
When using struts, the problem of Request.getrequesturi

Recommended Circles: Gt-grid
More related recommendation 1: variables defined in action, displayed in JSP page: <s:property value= "variable name"/>

2: In the page to implement the automatic increment of the serial number with iterator Statuts Index property eg:

<s:iterator value= "#request. Inoutaccountlist" id= "Data" status= "Liststat" >

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

</s:iterator>

3: Ways to get the request and session objects in the Action class

Map session = Actioncontext.getcontext (). GetSession ();
HttpServletRequest request = Servletactioncontext.getrequest ();

Ways to set their values

Session.put ("Operation", "add");
Request.setattribute ("name", name);

To get their values in the page:

<s:property value= "#session. Operation"/>
<s:property value= "#request. Name"/>

4: The page in the odd and even row style is not the same control method:

<tr class= "<s:if test= ' #listStat. Odd = = True ' >tableStyle-tr1</s:if><s:else>tableStyle-tr2< /s:else> ">

5: How to use the Radio box and check box

1): You can set the default check value, note the setting of the value of the list, this way to make key and value different, this method is more commonly used (CheckBoxList or radio)

<s:radio name= "Uncarinspolicy.policystatecode"
list= "#{' 5": ' Pass ', ' 2 ': ' Do not pass '} '
listkey= "Key"
Listvalue= "Value"
Value= ' 5 '
/>

2): The value of key and value is the same (CheckBoxList or radio)

<s:checkboxlist
list= "{' Red ', ' Blue ', ' Green '}"
Name= "FavoriteColor"/>

The tags in the 6:struts2 generate a string similar to that made by <tr><td></td></tr> (what tags are generated and the source of the generated page can be viewed) without limiting the generation of these unwanted code, The page will become uncontrollable, so generally we do not want it to generate redundant code, the specific setting method if, in the Struts.xml unified configuration
<constant name= "Struts.ui.theme" value= "simple"/> Plus this sentence can be
You can also cancel the default table layout by setting the tag's Theme property to "simple" in the page
However, it is best to customize a theme and set it to the default application to the entire site, so that you can get a unified site style

Ways to format dates in a 7:jsp page

<s:date name= "Uncarinsmodificationinfo.createtime" format= "Yyyy-mm-dd" nice= "false"/> This allows you to format dates into YYYY-MM-DD forms

8: By default, when the request action occurs, the Struts runtime (Runtime) instantiates the class of the action and invokes its Execute method, based on the set of Action mappings (Mapping) in Struts.xml. Of course, we can change this default invocation in the following two ways

1 creates a new action in Classes/sturts.xml and indicates the method it calls
For example, to call the action class

Public String aliasaction () {
Message = "Custom Action invocation method";
return SUCCESS;
}
Then add the following code to the Classes/sturts.xml:
<action name= "Aliashelloworld" class= "Tutorial". HelloWorld "method=" Aliasaction ">
<result>/HelloWorld.jsp</result>
</action>
This method can be invoked with an action name.

2) (more commonly used)

When you access the action, add "!xxx" (XXX is the method name) after the action name.

9:struts 2.0 has two profiles, Struts.xml and struts.properties are placed under web-inf/classes/.
Struts.xml for application-related configuration
Struts.properties configuration for the runtime (Runtime) of Struts 2.0

10: A way to get the physical path (absolute path) of a folder under the Web in the Action class
FilePath = Servletactioncontext.getservletcontext (). Getrealpath ("/uploadfiles")

11: To return to the page is not a direct JSP page but first by returning the action in the method to read the corresponding data and then return to the JSP page, there are two ways

1 in the Struts.xml so set

<result name= "list" type= "Redirect-action" >sysmanage/userbaseinfoaction!finduserbaseinfo.action</result >

2 Call this method directly when returning in action

return Findlist ();

12: How to set the default value in CheckBoxList

<s:checkboxlist name= "SKILLS1"
= "Skills 1"
list= "{' Java ', '. Net ', ' RoR ', ' 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 Two Drop-down box

<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"/>

Related Article

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.