MSB-STRUTS-classroom notes, Han shunping struts notes

Source: Internet
Author: User
Tags i18n xslt

MSB-STRUTS-classroom notes, Han shunping struts notes

A: Why does struts
Q:
1. built on the MVC model, MVC involves, but it mainly provides a good controller and a set of custom tag libraries, that is, it focuses on C and V, there are a series of MVC features, such as: well-structured, high-performance Yongxing, which increases the robustness and scalability of the program, facilitates the division of development and design, and provides centralized validation of internationalization and logs;
2. Open-source projects have been continuously and carefully cared for by programmers and experts, and have been tested in practice, making them more and more powerful and the system well-developed;
3. Other technologies and frameworks are well integrated. Integration with frameworks such as spring and hibernate
4. the development speed is greatly improved.

A: Framework concept:
Q: they are used to solve the same or similar type of problems.
1. Features: reusability, scalability, and shrinkage. The logical structure of the application Framework based on the request-response mode:
Controller business logic data logic)

A: concept and architecture of Struts
Q:
1. struts is an open-source project organized by Apache, mainly implemented by servlet and jsp technologies.
2. struts is an mvc framework based on the sun java ee platform. It uses the mvc model to fully leverage the mvc model's "separated display logic and business logic" capabilities.

A: Role of struts
Q: separate requests from views


A: some notice
Q:
1. The Filter in web. xml needs to be written /*
2. The action name is generally in lower case.
3. dtd is the file used by the xml prompt
4. namespace determines the action access path. The default value is ""
5. package is used to solve the problem of duplicate action names.
6. All results named success can be left blank. The default value is success.
7. when namespace is not written, it is "". You only need to enter the action name (for example, index), no matter how many layers of paths there are, as long as the name matches (for example, xxx/xx/index, xx/x/index can all access the index ).
When no package is written, when there are other actions (different namespaces) that cannot be processed by the package, it is handed over to the package that does not write the namespace for processing.
8. if the copy project is renamed, right-click the project properties, select web on the left side of the pop-up dialog box, modify the web Context-root on the Right To/the renamed project name, and redeploy the project, you can access the renamed project.
====================================
Action:
1. The returned view can be determined by the user-defined action.
2. The specific method is to find the corresponding configuration item based on the returned string to determine the beauty of the view.
3. the specific implementation of action can be a common java class, which contains the public String execute method, or the implementation of the action interface, but the most common is to inherit the ActionSupport, the advantage is that you can directly use the struts2 encapsulated method.
====================================
Three methods for customizing an action: 1. inherit from ActionSupport (recommended), 2 implement the action interface, Override execute (@ Override), and 3 Write public String execute.
-----------------------------
Public class indexAction1 {
Public String execute (){
Return "success ";
}
}
-------------------------------
Public class indexAction2 implements Action {
@ Override
Public String execute (){
Return "success ";
}
}
-------------------------------
Recommendation
Public class indexAction2 extends ActionSupport {
@ Override
Public String execute (){
Return "success ";
}
}
--------------------------------
Because:
ActionSupport has encapsulated a series of convenient methods that can be called directly. Including validate and input ....

Implementation of Action, method not used

First, you can't call it if you forget to write execute.
======================================
If a common class contains the execute method and the returned value is of the String type, it can be viewed as an action by struts.
====================================
A
Q:
1. struts2 is a new action object for each access.
Struts1 may use the same

2. struts1 Action is a singleton mode and must be thread-safe, because only one instance of Action is used to process all requests. the Singleton policy limits what Struts1 Action can do, and you need to be especially careful during development. action resources must be thread-safe or synchronized
The Struts2 Action object generates an instance for each request, so there is no thread security problem.

A: What will be executed if there are no classes in the action?
Q: by default, the execute method of ActionSupport is executed. Only success is returned.
========================================================== =
Path Problem description:
Access the project path directly to the web. xml, to the corresponding struts filter, and then find the corresponding namespace, if not, will return to the web. xml to tomcat for processing, will go to the web. in xml, find the <welcome-file> node under <welcome-file-list> to access the page.

A: The Path Problem in struts2 is determined based on the action path rather than the jsp path, so try not to use the relative path. Although the redirect method can be used, the single redirect method is not necessary (redirect is useless ).
Q: agree to use the absolute path (request. getContextRoot method is used in jsp to obtain the webapp path) or use myeclipse to specify the basePath.

If you add <base href = "<% = basePath %>"/> to the jsp head, no absolute path is required for all links on the page, by default, basePath is used to append the connection path.
======================================
June 21, Thursday 13
The execute method is not required when the Action is executed.
You can use method = to specify the methods to be executed when configuring actions in the configuration file (because too many actions are generated, it is not recommended ), you can also use the url address to dynamically specify (dynamic method call DMI) (recommended) Example: userAction! Add
======================================
Wildcard match: Call StudentAddAction. The action written in the configuration is 'student * '. When no matching action exists, the wildcard action is called. Method = {1} is configured. If the action name has eight asterisks, the order is arranged. 1 indicates the first asterisk.
Example: Call studentAdd. Configure the action name as student *, method {1 }. Add is the method name. Ps: You can also configure result. Example: <result>/studnet {1} _ success. jsp. Be sure to comply with the "agreement is better than the configuration ". For example, both add and delete

<Action name = "* _ *" class = "com. xx. Strtus2.action. {1} Action" method = {2}>
<Result>/{1 }_{ 2} _ success. jsp </result>
</Action> PS: the case must be the same !!!

NOTE: If two actions can be matched, the most accurate one prevails.
Example: Student_add, and *_*

If either of the two stars can be matched with each other, they are obtained in sequence. All asterisks belong to the same level.

====================================
When parameters are received using properties, if the action contains the name and age fields. When the page value is passed
You should call the set Method to modify the field, rather than directly modifying the attribute. So it doesn't matter if the field name is changed, but the value after the set method must be the same as the value sent from the page!

============================
Use the domain model to extract the field attributes and the getter and setter methods. In the action that calls an object, a private variable is generated. The private type name is used to write the get and set methods of the object.

Vo: value object
Do: data object
Dto: data transfer object
 
======================================
20140824
Domain Model: do not add a new object in the action, because struts2 will automatically create a new object.

Chinese problem: Do not use get if you have any Chinese characters. post is all used.
<Form action = user/user! Add "method =" post ">

I18n = internationalization is exactly 18 letters, so it is called i18n.

Struts2.1.6. If the i18n encoding is set to gbk in changliang, Chinese characters are garbled. This is a bug in 2.1.6. 2.1.7 will fix this bug.

In case 2.1.6, configure a filter before struts filter to solve the Chinese problem. Or change the struts filter to the filterDispatcher configured in 2.0. If you learn spring later, you can use spring filter to solve this problem.

<S: property> this parameter is used to obtain values in valueStack and context. The corresponding value stack value can be obtained based on the value stack name.

<S: debug> displays the value stack context information.

Struts places all attributes in struts valueStack, and then uses the <s: property> tag to retrieve the attribute values.

Struts will help us put the action attribute in the value stack, and we will directly use the <s: property> tag when getting the attribute.

The property name in the value stack is actually a map. For example, <s: property value = "error"/> if an error is obtained, the value {name = [name is error]} is obtained. The name in the result is the key of the map, the content in [] is value. if you want to obtain the content of a key in the map, use <s: property value = "error. name "/> indicates that the value is [name is error], and the value is an array. To obtain the first entry of the array, use <s: property value =" error. name [0] "/>.

An expression like error. name [0] is called an ognl expression.

ActionErrors is the information about a problem with the resource.
FieldErrors indicates the information used to verify the attribute.
Errors is the combination of the two.

======================================
Access the web elements request, session, and application:
1. Do not access response because the result is returned through the result, so you do not have to worry about response.
2. Obtain references of Map-type requests, sessions, applications, and real-type HttpSerletRequest, HttpSession, and ServletContext:
The first three are dependent on containers and IOC (this is only used)
The latter three: dependent on containers and IOC

Map request = (Map) ActionContext. getContext. get ("request ");

======================================
Question: Is ActionContext. getContext () A singleton mode?
A: It is not a Singleton, because each person's request is different, and the values in each request are different. If it is a Singleton, only one request can be put, the value is incorrect. Is the Tread Local object, the name of each thread and the corresponding value. In this thread is a singleton.
Notes:

Singleton mode: Singleton mode is a common software design mode. Its core structure only contains a special class called Singleton class. The Singleton mode ensures that there is only one instance in a class in the system and the instance is easy to access, so as to conveniently control the number of instances and save system resources. If you want to have only one class object in the system, the singleton mode is the best solution.

Key points: first, the singleton mode class only provides private constructor, and second, the class definition contains a static private object of this class, third, this class provides a static common function for creating or obtaining its own static private object.

Advantages: 1. instance control and 2. Flexibility
Disadvantages: 1. overhead (static initialization solves this problem), 2 possible development obfuscation (you must remember that you cannot use the new instantiated object), and 3 object lifetime (cannot solve the problem of deleting a single object. Cancel the allocation when providing memory management because it contains private references to the instance. In some languages (such as C ++), other classes can delete object instances, but this will lead to floating references in the singleton class .)
======================================
20140825
The attr in value stack context searches for values in request, session, and application one by one. But it is rarely used, because you need to know exactly where you want the value, otherwise it is difficult to determine which value is obtained when you encounter a duplicate name problem. (Should be forgotten !)
----------------------
IoC: inverse of control: if the result is controlled by others, it is called control inversion. It was first popularized by spring (not proposed by spring)
DI: dependency injection: If no container (external environment) injects this value, it cannot be obtained.

The request is rarely used, because the value stack itself is in the request. Application is rarely used. It can be stored in the database globally, or you can define a class by yourself. Sessions are commonly used.
--------- Default Action ----------
In the xml for configuration of pneumatic, configure the node <default-action-ref name = "default action name"> </default-action-ref> under the package to access the configured action.
----------- Action summary ------------------
1. The most common way to implement an action: Inherit from ActionSupport;
2. DMI dynamic method call
3. wildcard configuration * {1} {2}
4. Method for receiving parameters (generally receive parameters using properties or DomainModel)
5. Simple parameter verification addFieldError (generally, the Struts2 UI tag is not used
6. Access Web elements (1. MAP types a. Ioc and B depend on struts2. 2 original types a, Ioc, and B depend on Struts2)
7. Include File Configuration
8. The default value is how to process.
-------------------- FAQ ----------------------
1. if you use (Map) ActionContext. getContext. get ("request"); failed to get action, possibly web. in xml, It is configured as struts2.0 and must be configured with struts2.1. This is a bug!
------ Type attributes of resutl (dispatch, redirect, chain, redirectAction, freemarker, httpheader, stream, v elocity, xslt, plaintext, tiles )-------------------------
1. If this parameter is not set, the default value is dispatcher, which uses server jump, that is, jsp forward to go to a page. It can only jump to the page, not action.
2. redirect: You can only jump to the view.
3. chain: forward to an action
4. redirectAction: jump from client to action
/* The first four are commonly used, with emphasis on 1 and 2. It doesn't matter if you don't know about them later */
5. freemarker
6. httpheader: sends an http header.
7. stream: Download (it has nothing to do with upload)
8. velocity (the template framework is no longer freemarker ):
9. xslt: xml-related Modifier
10. plaintext: displays the website source code (not html), which may be used for teaching websites. It is not used in other cases.
11. tiles.
======================================
2014.9.2
1. global result: if there are many actions, they all have a common result. Instead of configuring them in each action, it is better to configure a global result. In a package, all actions can share a result.
<Global-results>
<Result name = "mainpage">/main. jsp </result>
</Global-results>

2. If another package wants to use the global-result of this package, extends will inherit the package containing the global-result.
3. If a packet contains abstract attributes, this package is specially used for inheritance.
4. interceptor and filter have the same principle.
5. dynamic result (not much is used, you can understand it): <result >$ {r} </result>, r is the attribute in action, set the r value before the return, read the R value in the configuration file. $ Is the OGNL expression used to read the value in valueStack in the configuration file.
6. One request has only one value stack, so the server-side forward is one request for the client, so the two of them share one request.
7. If the result type is redirect, you need to pass the valuestack parameter and write it in the result.
<Result type = "redirect">/x. jsp? Parameter Name =$ {parameter value object}
8. If you use forward, you do not need to pass parameters. When you use redirect, # parameters is required to pass parameters.
==================================
Result summary:
1. Four types are commonly used (the above two types are commonly used, and the following two types can be used for understanding ):
A. dispatcher (default)
B. redirect
C. chain
D. redirectAction
2. Global result set
Global-results: to use the global result set of another package, use the extends package.
3. Dynamic results (understanding)
Save an attribute in the action to store the specific result location. The $ {} (not el) value is required.
4. PASS Parameters
A. Client redirection is required
B. s {} value from valuestack, not el
========================================
Take a look at the document, go to gogle, and finally ask people around you.
========================================
Action
1. The most common way to implement an action: Inherit from ActionSupport
2. DMI dynamic method call: Action! Method
3. wildcard configuration * {1} {2}
4. Method for receiving parameters (generally receive parameters using properties or DomainModel)
5. Simple parameter verification addFieldError. Generally, the Struts2 UI tag is not used.
6. Access web elements a and Map (IoC, dependent on struts2); B. Original Type (IoC, dependent on struts2)
7. include File configuration: include
8. defaactionactionreferents is handled by default action (learn more)

Result
1. Four Common types: dispatcher (default), redirect, chain, redirectAction
2. global result set global-results extends
3. Dynamic results (understanding): save an attribute in action and store the specific result location.
4. Pass parameters: a. The client jump must be passed. B and s {} expressions (not el)
======================================
OGNL
1. In an OGNL expression, if you do not manually create a new object when passing parameters, the framework will automatically construct the object only after passing the object attributes. Otherwise, the object is empty.
2. domain model generally provides the Default Construction Method without parameters, because if the Framework automatically instantiates an object, it will call the construction method without parameters. If there are eight constructors, parameters must be passed, there is no parameter-free constructor. In this case, the framework will not automatically instantiate the object (the Framework does not know which parameter-based constructor to choose and how to pass these parameters ).
============================================
Ognl
Object Graph Navigation Language
============================================
Struts labels (no struts labels are needed when the program is properly designed)
I. general labels
1. property
2. set
A. The default value is actionscope, which puts the value in request and ActionContext.
B. page, request, session, application
3. bean
4. include)
5. param
6. debug
Ii. control tags
1. if elseif else
2. iterator
A. collections map enumeration iterator array
3. subset
3. UI tag
1. theme
A simple xhtml (default) css xhtmlajax
Iv. AJAX labels
1. Supplement
V. Differences between $ # %
1. $ user i18n and struts configuration file
2. # obtain the ActionContext Value
3.% parses the original text attribute struts2 into ognl, and does not work for the attribute originally named ognl
-------------------------------
Important labels:
1: property, set, bean, param, debug
2. if elseif, iterator
Ajax is the most primitive,
For more information, see.
-------------------------------
20140924:
I. Declarative Exception Handling
1. Perform exception ing in Action
2. perform global exception ing in the package
3. Use the inherited public exception ing
4. Exception Handling in struts2 is implemented by the Interceptor (observe the struts-default.xml, in fact most of struts2's functions are implemented by the interceptor)
I18N (International website)
1. Principle:
A. Concepts of ResourceBundle And Locale
B. Resource file
C. native2ascii
2. struts resource file
A. Action-Package-App level
B. PropertiesEditor plug-in (decompress the plug-in and overwrite the features plug-in to the eclipse directory in myeclipse)
---------------------------
The package-level I18N resource file must start with package _ (this method is rarely used (too troublesome, too many settings). Generally, it can start with the entire application-level I18N, must be placed under the project root path, and then in struts. configure constant in xml: struts. custome. i18n. resources = Name starting with the resource file)
---------------------------
Parameters in the resource file, and write placeholders in the resource file, such as: welcome. msg = wel: {0}
<S: text name = "welcome. msg">
<S: parame value = "usernmae"> </s: param>
</S: text>
Welcome. msg will be displayed when it cannot be obtained.
---------------------------
Dynamic Language Switching
Url with parameters :? Request_locale = en_US. After submission, the entire website is in English.
======================================
Struts interceptor and source code parsing
1. struts architecture diagram (see the desktop and struts process)
2. struts Execution Process Analysis
3. Interceptor Process Simulation
4. define your own Interceptor (rarely used, but the design is incorrect because most of the interceptor struts has been designed. If you customize the struts interceptor, it is equivalent to binding together with the struts framework. If you want to switch to another framework, it will be over ......)
A. For example, acegi (formerly known as)-spring security (renamed): for example, determining permissions in class methods or URLs
5. Use the token Interceptor to control repeated submission (rarely used)
6. Date Processing
7. type conversion
A. Write your own Interceptor (inheriting defatypetypeconverter and rewriting convertValue)
B. Three registration methods
Ba. Local: XXXAction-conversion.properties (to be placed in the same package as action)
P (attribute name) = converter
Bb. Global: xwork-conversion.properties
Com. xx. xx (type) = converter
Bc. Annotation (@ element)
If you encounter a very troublesome ing conversion request. setAttribute ();
============================================
Struts2 Summary
--------------------------------------
1. Action: namespace (master), path (master), DMI, dynamic method call, action! Method (master), wildcard (master), receiving parameters (master the first two action attributes and domain model), access request, etc. (master the map ioc method), simple data verification (Master addFieldError and <s: fieldError>)
--------------------------------------
2. Result: There are four types of results (redirect and dispatcher), two types of results (master), and dynamic results (understand)
--------------------------------
3. OGNL expressions (proficient): # % $
-------------------------------
4. struts labels (common)
4. Declarative Exception Handling (understanding)
5. I18 (learn more)
6. CRUD process (most importantly, design and planning) proficient
7. Interceptor principle (master)
8. type conversion (learn more about customization by default)


How do I take classroom notes?

1) Keep up with the teacher's ideas
I carefully previewed the lesson, not to say that I can relax my mind when I listen to the lesson. We should listen carefully and follow the instructor's ideas. One student summarized the following methods:
1. Listen carefully and follow the instructor's ideas (what is the key and what is the difficulty ......);
2. I didn't understand it. I made a mark first. After class, I kept up with the teacher's explanation;
3. Try to digest the knowledge given by the teacher;
4. The brain should be as sharp and nervous as taking the test.
5. Take notes. The notes mainly consist of two aspects: first, the content that is not found in books, and second, the content that is not understood in class.
In short, the teacher's thinking is the essence of a lesson. Grasping the teacher's ideas is equivalent to grasping the essence of a lesson.
(2). Pre-loose and post-Tightening Method

The so-called "loose and tight before" means that you may relax a little a few minutes before the lesson, and then get nervous again later. A 45-minute lesson and several classes a day is hard to tell the truth if you want to listen nervously and intently from beginning to end. Therefore, the national college entrance examination in Hebei Province, the third class of science and engineering students believe that the lesson may be loose before and after the tight. He said that some students can concentrate at the beginning of the lesson, but they can start to become distracted at the beginning. Teachers often start to review previous content and introduce new content at the beginning of the lesson, these are often relatively simple, and the next step is more in-depth analysis and explanation. These are the most important things. However, at this time, many of you are already absent-minded. Therefore, you may wish to do the opposite. Just relax and then get nervous in the second half of the class.

According to psychologists, the attention of teenagers generally lasts for 20 to 20 seconds ~ 25 minutes. Beyond this time, attention will drop. Some people have investigated the length of time for lectures by 100 students (50 boys and 50 girls) in senior one. Most students think that a class lasts for 45 minutes. 45% of students think that the length of the course is too long ~ 40 minutes is recommended, 37% of students think 20 ~ The best time is 30 minutes. Even 13% of students claim that a class is about 20 minutes. In this way, there is a certain conflict between the duration of attention sustainability and the 45 minutes of normal teaching.

If the class is "tight and loose", the first half of the class will still be able to stay focused. When the second half of the class begins to relax consciously. The content of classroom teaching is often the opposite. The second half is the main play. Therefore, you may wish to relax before the lecture.

(3) write down the instructor's lecture content with emphasis

Note taking varies with different disciplines. For example, some concepts and theorems in mathematics, physics, chemistry, and other disciplines are available in books. They have complete content, rigorous statements, and are scientific and logical, so you don't have to remember them. It focuses on the teacher's explanation of the concept, the points to be paid attention to in understanding and the problem-solving skills. In political courses, I mainly want to record the points of how the teacher interprets nouns and concepts in a more popular and more vivid way than in books, and then how to relate theories to reality, this helps you master the correct ideas and methods. A Chinese Lesson mainly records the background of the text, the characteristics of the text, the usage of some words and the relevant content provided by the teacher, and a foreign Lesson mainly records the usage and differences of words. In short, classroom notes are mainly used to explain the key points and difficulties in the teaching materials, summarize and summarize some content, and record the Teachers' Ideas for solving problems or their unique insights. Especially for those who do not understand and the teacher's explanations are inconsistent with their own understandings, you need to write them down for later study and comparison. In this way, I am most impressed with my knowledge and enjoy the greatest benefits.

(4). Sort out notes in seven steps"

After learning to take notes, we also need to take notes. Because only the organized classroom notes can become clear, organized, and useful reference materials. Gu jiafei, a member of Shanghai Nanyang model Middle School, created a set of "seven steps to sort classroom notes", which is of great practical value. The seven steps are as follows:

Step 1: Recall. After class, take time to compare books and notes and recall relevant information in a timely manner. I really cannot recall it. You can refer to it through your notes. This is an important prerequisite for organizing notes and provides the "conciseness" for notes ".

Step 2: complete. Note made in the class, because it is necessary to follow the speed of the teacher's lecture, the general speed of the lecture is faster than the record speed. Therefore, notes may be missing, skipped, or even replaced by symbols. Make timely repairs on the basis of memory, so that the notes have "integrity ".

Step 3: change. Carefully review the notes to check whether the incorrect words, incorrect sentences, and other words are adequate ...... the remaining full text>

Han shunping struts class notes

Sent to qq? Only notes! Organized by yourself! Or not?

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.