Struts (i)

Source: Internet
Author: User

===============================mvc====================================
MVC (Model View Controller)
1.Model: Encapsulate data, perform business processing, return processing results
2.View: Display Interface
3.Controller: Accept client requests, connect models and views together to implement user-requested functionality

Ideas: Pictures

==============================struts===============================
Introduced:
1.STRUTS2 is an MVC framework. Struts1 + webwork
2.struts2 Good compatibility
3.http://struts.apache.org

Steps:
1. Loading the class library
2. Configuring the Web. xml file
3. Developing the View Layer page
4. Develop control-level action
5. Configuring the Struts.xml File
6. Deploy and run the project

A. Load the basic jar package:
Core class Library of the Struts2-core-xxx.jar Struts 2 framework
Xwork-core-xxx.jar Xwork Class Library, the foundation for the building of Struts 2
Ognl-xxx.jar Struts 2 uses an Expression language class library
Freemarker-xxx.jar Struts 2 label templates use class libraries
Javassist-xxx. Ga.jar byte code processing
Commons-fileupload-xxx.jar file upload needs to be used
Commons-io-xxx.jar Java IO Extension
Commons-lang-xxx.jar contains a number of data types of tool classes

B. Configuring Web. xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>
Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>

<!--position all requests to the specified STRUTS2 filter--
<url-pattern>/*</url-pattern>
</filter-mapping>

STRUTS2 Access Servlet API--(i.e., after successful login, use session to save user information)
Access method:
1. Decoupling
A. Encapsulating the Servlet API
Provides three map objects to access the request, session, application scope
B. Get these three map objects through the Actioncontext class
1) Object Get ("request")
2) Map getsession ()
3) Map getapplication ()

2. Coupling
A. Getting a servlet API object from the Servletactioncontext class
1) ServletContext Getservletcontext ()
2) HttpServletResponse GetResponse ()
3) HttpServletRequest Getrequest ()
4) Get Session object by Request.getsession ()
B. Passing data on different pages or actions through the Xxx.setattribute () and Xxx.getattribute () functions

Data validation:
1. Inherit the Actionsupport class to complete the action development
Validate () method
The 2.ActionSupport class not only makes simple implementation of the action interface, but also adds support for validation, localization, etc.

Label:
1. Send the action error message to the page output
<%@ taglib prefix= "s" uri= "/struts-tags"%>

Common form Labels:
Label description
<s:form>...</s:form> Forms Labels
<s:textfield>...</s:textfield > Text input Box
<s:password>...</s:password > Password entry box
<s:textarea>...</s:textarea > Text field input box
<s:radio>...</s:radio > Radio button
<s:checkbox>...</s:checkbox > Multi Box
<s:submit/> Submit Tag
<s:reset/> Reset Label
<s:hidden/> Hidden Fields tab

2. Use the Struts 2 tab to implement logical control in the page
A. Using the universal label for Struts 2
B. Conditional Judgment label
C. Iteration labels

Common Common Tags:
Name Label description
Criteria label <s:if>......</s:if> based on the value of the expression,
Determine what is going to be done <s:elseif>......</s:elseif>
<s:else>......</s:else>
Iterative <s:iterator>......</s:iterator > for traversing collections
"Note: In actual development in order to meet the increasingly diverse needs of users. It is recommended to use native HTML as well as El Expressions and Jstl tags to accomplish these functions "




















Struts (i)

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.