Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of some commonly used attributes and examples in Struts

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Struts in some common attributes and sample analysis, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

Struts-config.xml is very important in struts learning. Let's first talk about the processing flow of struts implementing MVC pattern: First, the foreground information is obtained from the jsp page and stored in ActionForm. The configuration information is in struts-config.xml. Then the central controller ActionServlet intercepts the information, calls the information in ActionForm and struts-config.xml, and then decides to distribute it to specific actions. The action calls Model to process and return the page. However, in the actual project, it is not only the page, but also other things. Then return to the browser.

The whole process is like this, struts also has a series of tag library, more commonly used, to use this tag library, need to import in the page, then you can use the tag library, prefix is bean, then you can use the tag library, prefix is bean. bean:write is equivalent to the name where something is an attribute. The following bean:write details are as follows:

bean:write has the following properties:

1。name, used to specify the name of the attribute

2。filter, used to specify whether to mask the HTML format of the attribute value

3。property, used to specify the property name of the object represented by name

4。format, used to specify the format of time, number, date, etc. displayed

Example 1:

request.setAttribute("hello","hello world") is set somewhere;

Then in a jsp page, the write tag of struts is used to extract and display as follows:

The page shows Hello World.

Example 2:

request.setAttribute("bj","Welcome") is set somewhere;

Then in a jsp page, the write tag of struts is taken out and displayed in red as follows:

A red welcome appears on the page. If the filter property is not set to false, the default is true, and the content displayed is welcome.

Example 3:

request.setAttribute("date",new Date()) is set somewhere;

Then in a jsp page, the method of extracting and displaying the date in the specified way with the write tag of struts is as follows:

< bean:write name=""date"/" >

, This is the default display method, the displayed time is: Sun May 10 20:47:31 CST 2009

< bean:write name=""date"" HH:mm:ss" format=""yyyy-MM-dd" >

< / bean:write>

, This is the display format of the date specified by yourself, and the displayed time is

2009-05-10 20:47:31

Example 4:

request.setAttribute("n","122333.333") is set somewhere;

Then in a jsp page, the method of extracting and displaying numbers in the specified way with the write tag of struts is as follows:

, This is the default display method, the displayed digits are 1223333.333

, This is the display format of the number specified by yourself, and the displayed time is 1, 223, 333.333

If you want to fill in 0 when there are less than four decimal places after the decimal point, you should

, This is the display format of the number specified by yourself, and the displayed time is 1, 223, 333.3330

Example 5:

If there is a User class and a Groupe class, the User class has the attribute name userName, age, gender sex, and the Groupe to which it belongs, and the Groupe class has the attribute group name groupName, and has the corresponding get and set methods.

request.setAttribute("user",new User ("Zhang San","20","male", new Group ("three groups"))) is set somewhere;

Then in a jsp page, the method of extracting and displaying the structure in the specified way with the write tag of struts is as follows:

User Name:

< INPUT value=""< bean:write" type="text" name="user" property=""userName"/" >

"> Age:

< INPUT value=""< bean:write" type="text" name="user" property=""age"/">

"> Gender:

< INPUT value=""< bean:write" type="text" name="user" property=""sex"/" >

"> Group Name:

< INPUT value=""< bean:write" type="text" name="user" property=""groupe.groupeName"/" >

"Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report