Use the Annotation configuration of Struts2
1. Case study: log on to the success. jsp page by entering the Logon account on the loginUI. jsp page. If an error occurs, the error. jsp page is displayed.
Ii. Case study: simple configuration is required for downloading struts2 files.
A) Find the struts2-convention-plugin-2.3.15.3.jar, asm-3.3.jar, and asm-commons-3.3.jar In the downloaded struts lib package in the project lib folder. The annotated packages provided by Struts.
B) Create the loginUI. jsp page and enter the account and password.
C) on the create success. jsp page, "registration successful" is displayed.
D) The error. jsp page displays "registration failed.
E) Create LoginAction. java. Use annotations for configuration.
@ParentPackage("struts-default")@Action(value="login",results={@Result(name="success", location="/success.jsp"),@Result(name="input", location="/error.jsp")})
F) we can view the class in the org. apache. struts2.convention. annotation package under the struts2-convention-plugin-2.3.15.3.jar, through the class name we can find that the labels in struts. xml are basically one-to-one correspondence.
G) minor issues left in "Struts2's struts2 File Download details. In the document download chapter, we will discuss how to discover and solve the problem. I did not explicitly say that I would leave a question for everyone. So today I want to ask who found the question of "Chinese Garbled text. To find this problem, you must first dynamically generate the name of the downloaded file, instead of directly configuring it in struts. xml. First, generate a member variable in the action, and then configure the name of the downloaded file: attachment; filename = "$ {member variable }". In this way, the downloaded file name will be garbled in Chinese. The solution is to assign a value to the member variable and then transcode it. For example, the member variable = new String (member variable. getBytes ("gbk"), "8859_1. If you have not considered this issue, do you have to reflect on it.
Iii. Experience:
A) Do you sometimes like to use new features in your own projects? For example, in struts2, struts is used. xml configuration of action, I like to use annotations in the back-to-normal way, and it seems like I have many coops. In fact, I am not saying that the annotation is not good, nor does it mean that I am not so powerful. All functions and annotations that can be implemented by Struts. xml can be implemented, but later management will be very troublesome. It can be said that annotations are just to adapt to the development of the industry. You cannot say that spring has annotations, and struts does not. That's what I mean. You only need to remember what you understand. In actual projects, we mainly use struts. xml. If you don't want to use fresh things, wait for spring to give you enough. Annotations are mainstream in spring.
B) In our struts version using annotations must add asm-3.3.jar, asm-commons-3.3.jar two jar packages, otherwise the class will not find the exception, 2.2.1.1 is not added. Other versions are not tested yet.
4. Reference project: http://download.csdn.net/detail/u011638419/8226523
5. happy every day:
My son came back from school yesterday and said to his mother, "now I finally know what I used when my dad gave birth to me,
Is used to fight ."
The right to final interpretation belongs to partner aishang (www.23hhr.com). Please indicate the source for reprinting.