It is well known that the Internet is based on the HTTP protocol and HTML language. User Agent uses the HTTP protocol as an HTTP protocol as a web browser, and then the browser is responsible for formatting and displayed to the user. The HTTP protocol used is transmitted, and HTML is a general language used by the web and web applications.
When performing a web application development, some Java programmers may write HTML languages themselves, and some will be handed over to dedicated page designers.
About HTTP, HTML, and User Agents more knowledge can refer to the following resources:
Getting started with htmldave raggett; http overview in Java Web Services Tutorial; HTTP / 1.1 specification; HTTP Basic and Digest Authentication Specification; cookies;
0.3 HTTP Request Response Period For web developers, the most concerned about HTTP is the request response cycle of HTTP, submit a request with HTTP, and then the HTTP server (such as a web server) returns a response. When we perform web development design, we are designed as an HTTP request to return an HTTP response. The Struts framework is abstracted in this cycle, and more important to us should know what happened behind. If you are not familiar with the HTTP request response cycle, then we strongly recommend you to read the HTTP Overview 0.4 Java Language and Application Framework in Java Web Services Tutorial.
The Struts framework is the most popular universal programming language when using it (the translator's Note: I feel that it is not over the Java language) Java. Java is an object-oriented programming language, and Struts is using its object-oriented technology. In addition, Java itself has a good support for threads that can perform multiple tasks at the same time. Very good understanding of the Java language, object-oriented programming and threads, which is beneficial to we master Struts and use this user guide.
Learning Java language and threads can refer to the following information:
The Java Tutorial Learning The Java Language; The Java Language Tutorial Learning The Threads Doing Two or More Tasks at OnCE;
Even if you have used Java and object-oriented programming, create and use the application framework to program your programming. More knowledge about the application framework, you can refer to the following two white paper:
Designing Reusable Classes Ralph E. Johnson and Brian Foot; Object-Oriented Application Frameworks Mohamed Fayad and Douglas C. Schmidt;
If you are looking for a server-side framework, these two pages may have some help: 1 and 2
0.5 javabeans
Like many Java applications, most Struts objects are also designed to javabean. Use the JavaBean design pattern to make the Struts class easier to be used by Java developers and Java deployment tools.
Javaban was originally created for visualization element, and now this object design pattern has been widely applied to the basic design of more reusable components, such as Struts frameworks.
About javabean more knowledge, refer to:
java.sun.com in The JavaBeans Component Architecture Documentation and JavaBeans 1.01 Specification; The Java Tutorial in The JavaBean Trail; The Java Web Services Tutorial in the JavaBeans Components in JSP Pages; 0.5.1 reflection and introspection
Reflection is the determination of which member variable or method of the object is a process mechanism that is available. The province is a special form of reflection used by JavaBean API. Using within the province, we can know which methods of JavaBean can be accessed by other objects.
The STRUTS framework uses the internal provincial mechanism to convert the HTTP parameter to the JavabEan property and use the Javabean property to assemble the HTML form field. This technology makes "two-way access" attributes between JavaBean and HTML forms more simple.
For more, please refer to:
The Reflection Trail; Chapter 8 of the JavaBeans API Specification;
0.5.2 Mapping (MAPS)
JavaBeans operates this data in other methods by storing data using attributes. JavaBean is a convenient and powerful object, but it is not the only choice for programmers to store data. Another popular object is mapping (MAP) java.util.map ?. A mapping is a simple name value to a collection. Mapping is often a convenient way to store dynamic data as a "behind the scene".
0.5.3 Dynamic Bean (Dynabeans)
Dynamic bean set JavaBean scalability and MAP flexibility in one. We know that even if you want to define a simple JavaBean, we have to create a class, define a property variable, and two access methods corresponding to each attribute (setxxx and getxxx). Dynamic beans can define properties through an XML configuration file. The virtual properties of dynamic beans cannot be called like a normal Java method, but to access by components using reflection and internal provinces (Introspection) mechanisms.
In the Struts framework, you can use dynamic beans to describe an HTML form. This policy avoids we have to create a formal JavaBean subclass for some simple form fields.
For more dynamic beans, please refer to:
Jakarta Commons project beanutils's Package Description and Javadocs;
0.6 Properties file and resource binding (Resours bundles)
Many Java applications (including web applications) are often configured by attribute files. The attribute file is the foundation of the Struts framework for providing a message resource resource binding to the application.
For more information on attribute files, please refer to:
The USING Properties to Manage Program at The Java Tutorial provides international support to users based on one or more attribute files based on the user area (LOCALE). Struts has a good support from a localization of an application from a building. For more information on localization and resource binding, please refer to: About The ResourceBundle Class in The Java Tutorial
0.7 Java Servlet
Since Java is an object-oriented programming language, the Java Servlet platform will put HTTP forced shape (or construct) as an object-oriented form. This strategy makes Java developers save more time to deal with their application, not on HTTP mechanism processing. HTTP provides a basic mechanism for extended servers, namely, Commons Gateway Interface (CGI). The server can pass a request to the CGI program, then the CGI program returns a response. Similarly, a Java server passes a request to a servlet container, the container can be processed for the request, or the request can be returned to the HTTP server, and the container checks its servlet list to determine whether to process this request, if request Registered a servlert, then the container is transferred to this servlet.
When a request is entered, the container checks if the request is registered with a servlet. If a matching servlet is found, the container passes this request to this servlet. If not, the request is returned to the HTTP server.
The responsibility of the container is to manage the lifecycle of the servlet, create a servlet, call the servlet, and finally release the servlet.
Under normal circumstances, a servlet is a subclass of [javax.servlet.http.httpservlet], and a servlet must implement four methods that the container needs to be called:
Public void init (servletConfig config): When the servlet instance is first created and executes all requests, the servlet container calls this method; PUBLIC VOID Doget (HTTPSERVLETREQUEST REQUEST, HTTPSERVLETREQUEST, HTTPSERVLETREQUEST, HTTPSERVLETRESE RESPONSE) This method is used to process requests using the HTTP GET protocol Generate a corresponding dynamic response; PUBLIC VOID DOPOST (HTTPSERVLETREQUEST REQUEST HTTPSERVLETRESPONSE) This method is used to process a request to use the HTTP POST protocol and generate a corresponding dynamic response; public void destroy () When the Servlet instance is aborted The container calls this method, such as when the web application is being used by Undeploy or when the entire container is subjected to Shut Down;
The Struts framework has provided a ready-made servlet [org.apache.struts.Action.ActionServlet]. As a Struts application developer, in the use of the ActionServlet instance of the Struts framework, understand the basics of servlets and understand the role it played in a web application is also quite important.
For more knowledge about servlet, please refer to:
java.sun.com in The Java Servlet Technology; java.sun.com in The Servlet 2.2 and 2.3 Specifications; The Java Web Service Tutorial of Java Servlet Technology; The Java Web Service Tutorial of Web Applications;
0.7.1 servlet and thread
In order to improve performance, the container supports multi-threaded servlet. A concrete servlet can only create an instance and serve each request service for this servlet through the same object. This strategy allows the container to make full use of system resources, and at the same time, it is necessary to consider thread security issues encoded by servlets and dopost methods. For more information on servlet and thread security, please refer to:
Controlling Concurrent Access to Shared Resources in The Java Web Service Tutorial;
0.7.2 Servlet Context (Context)
ServletContext interface [javax.servlet.servletContext] provides views of the context (or environment) of the web application where the running servlet is run. Servlets can be accessed via GetServletConfig () method, while JSP pages can be obtained by implicit variables Application variables. Several APIs provided by the servlet context are quite useful when creating a struts web application.
Accessing the web application resource: servlet can access static resource files within the web application via the getResource () and getResourceSstream () methods; servlet context properties: context can be used to store Java objects, identify objects via string values, these Attributes are globally over the entire web application, servlets can be accessed via getAttribute (), getAttributeNames (), RemoveAtribute (), and SetAttribute () methods. For JSP pages, servlet context properties are equivalent to "application scope beans";
For more information on the servlet context, please refer to:
Accessing The Web Context in The Java Web Services Tutorial;
0.7.3 Servlet request
The request for each servlet is represented by a Java interface, typically HTTPSERVLETREQUEST interface [javax.servlet.http.httpservletRequest]. This request interface provides an object-oriented mechanism access to all information contained within the underlying HTTP request, including:
Cookie: Get a valid cookie set contained in the request via the getCookie () method; header: Access to the request included in the request via the name. You can enumerate all the names of all HTTP headers; parameters: request parameters, can access the request parameters contained in the URL in the query string (DOPOST) in the request content (request feature: input Some other features such as the HTTP request, such as the protocol specification ("http" or "https") used by the GET or POST method ("http" or "https"), etc .; request URI information: The original request URL can be obtained through the getRequesturi () method. In addition, the servlet container parses the request URL to some components that can be accessed (ContextPath, ServletPath, and PathInfo; user information: If you use user management security, then you can find a certified user name and get a representative The current user's Principal object, and whether the current user is authorized to be a specific role;
In addition, the servlet request also supports request attributes (in JSP, requiring the scope bean), similar to the previous servlet context properties. The request attribute is often used in status information communication between the business logic layer and the view layer, and the service logic layer generates these status information, and the view layer uses this information to generate a corresponding response. The servlet container will ensure a specific request to be handled by a separate thread, so you don't have to worry about the problem of thread security when accessing the service request.
For more requests for servlet, please refer to:
Getting Information from Requests in The Java Web Tutorial;
0.7.4 Servlet Response
The main purpose of a servlet is to process an input servlet request [javax.servlet.http.httpservletRequest] and generate a corresponding response. The process of generating a response is done by calling the SERVLET response interface [javax.servlet.http.httpservletResponse], the available methods are as follows:
Set http header: You can set the HTTP header information contained in the response. The most important http header information is Content-Type, which tells you that the client contains which type of information in the responder, in general, set to the TEXT / HTML type is the HTML page, or set to text / XML type That is the XML document; set cookies: You can add cookie to the current response; send an error response: You can send an HTTP error status information (instead of the general page content) using senderro (); redirect to other resources: You can use SendRedirect () method is replaced to the client to the other URL resources you specify;
An important principle to respond to the API using the Servlet is that all methods of calling the maintenance header information and the cookies must be completed before the cache is first updated to the client. The reason is because this information is transmitted as the http response, and therefore, attempting to add header information after the header information has been sent, it is inevitable.
With the performance layer of the application using the Model 2 mode, you may not use the servlet response APIT to generate a response. Generally, the JSP page is used, and the JSP page in the servlet container will be converted by the JSP compiler to servlet, which is generated by this JSP Servlet, which may contain some dynamic information generated by JSP tags.
Other performance systems, such as the Struts Tools Velocity Framework, which may cause the task agent generated to generate a dedicated servlet, but the principle is the same. You create a template and then dynamically generate by template.
For more than the servlet response, please refer to:
Constructing responses in The Java Web Tutorial;
0.7.5 Filter (Filtering)
If you use a version 2.3 or update specification (such as Tomcat4.x), you can use the new filter APIS [Javax.Servlet.Filter] to process requests and generate responses. The filter is actually a collection of filter chains, each filter can handle requests and generate responses, then handle the processing right to the next filter, and finally call the servlet.
Struts 1.x Series (1.0, 1.1 versions, etc.) only supports a 2.2 version or earlier Servlet specification, Struts itself does not use a filter. The next generation of Struts (2.x series) is based on servlet2.3 or update specification. The Struts 2.x version may be used in the filter. For more filters, please refer to:
Filtering Requests and Responses;
0.7.6 Session (Session)
HTTP's most critical feature is stateless. In other words, the HTTP built-in mechanism cannot identify the same user in subsequent requests and its relay requests. This makes it quite difficult to build an application for a cross-request user interaction!
To overcome this difficulty, Servlet APIs provide a programming concept - session, indicated by an object that implements the [javax.servlet.http.httpsession] interface. The servlet container will use the cookies or rewritten the URL two techniques to ensure that the session ID of the same user's session is included in the next request, so that the status information saved in the session can be associated with multiple requests. Status information is saved in session attributes, in the JSP page, is the "session scope bean".
In order to avoid a user who has permanently occupied a resource during failure to complete an interaction, the session can configure the timeout interval of the session. If the time interval between the two requests exceeds the configured timeout time interval, the session will time out, all session properties will be deleted. You can define a default session timeout interval in the Configuration Descriptor file of the web application, or you can dynamically change the timeout interval by calling the setMaxINactiveInterVal () method in a specific session.
Different sessions and requests differ in that the problem of thread security should be considered when using session properties, and request attributes are not available. (Not only the session itself getAttribute () and setattribute () methods, and all the methods provided by these beans) Sessions make the same user's multiple synchronous requests, because they can access the same session.
Another problem that should be considered is that the session attribute between the request should take a certain server memory resource, which may affect the number of synchronous users supported by the system. If your application needs to support a large number of synchronous users, you should use the session properties as soon as possible to control your entire application to memory needs.
For more session, please refer to:
Maintaining client state; javax.servlet.http.httpsession; Javax.Servlet.http.httpsession in The Java Web Tutorail;
0.7.7 Dispatch Requests
The Java Servlet specification extends the request / response cycle of HTTP by distributing, forwarding requests between resources. The Struts framework uses this feature of Servlet to allow a request between several specific dedicated components, each component may affect the content of the response. The general process is such that one request is first grasped by the controller component, followed by the model component, and is finally given to the view component, which may be just a separate request / response cycle.
0.7.8 Web Application
Not only can an HTTP server can host multiple separate Web sites, but the servlet container can also serve multiple web applications. The Java Servlet platform has a clear mechanism for organization and deployment web applications. Each web application runs in your own namespace, you can deploy separately and separately. A web application can be a web application file, or a WAR file. A separate WAR file can be uploaded to the server and deploy it automatically. For more web applications, please refer to:
Web Applications in The Java Web Tutorial;
0.7.9 Web Application Configuration Descriptor File (Web.xml)
In the lifecycle of the application, the properties and events can be configured through the web application configuration descriptor file XML file. The configuration file Web.xml mode is given by the Java Servlet specification.
For events in web.xml and application life cycle, please refer to:
Web Application Life Cycle in The Java Web Tutorial;
0.7.10 Security (Security)
The security of container management can be configured in the web application configuration file. The statement of the declaration can protect the request to match the URI of a certain mode. Programming level is safe for microscopic security control, such as timing, calling parameters or authorization control within the internal state of the web component; or based on a database-based constraint verification.
For more information on container management, please refer to:
Web Application Security (Chapter 24) in The Java Web Tutorial;
0.8 JSP, JSP Tag Library and JSF
JSP is actually essentially servlet, which is a servlet that makes the creation and maintenance dynamic web page. All of the JSP pages except in these specific Java statements will be written to the HTTP response in place of the HTTP response in place of the Java's print statement.
With JSP, you can start from a standard HTML page, then add some dynamic characteristics using the Java language or JSP tab. The Struts framework itself contains some JSP tag libraries that allow you to easily access the features of the frame in the JSP page.
For JSP and custom JSP tag libraries, please refer to:
JSP technology page for java.sun.com; JSP 1.1 and 1.2 specification downloads in Java.sun.com; JSP technology in The Java Web Services Tutorial; JSP custom label in The Java Web Services Tutorial;
Many times the JSP tag is used together. The application sends a JavaBean to the JSP page, the JSP tag uses beans to customize the page for the current user. For more, please refer to the JavaBean component in JSP in The Java Web Tutorial
Struts can be used well with the new JSP standard tag library (JSTL), and there is also a good compatibility with other label libraries, such as JSP Tags and Jakarta Taglibs.
There are also other useful toolkits to make the Struts framework easier, such as XSLT and Velocity Templates.
The latest new star on the Java skyline is Java Server Faces. JavaServer Faces technology simplifies creation of user interfaces of JavaServer applications (including Web and desktops). Although the JSF specification is still in the development phase, the Java Web Services Developer Pack already contains the available initial reference implementation version. Similarly, the JSF tag library of the Struts framework has completed the initial version through the efforts of the night ending day. The JSF and Struts framework are fully compatible. With the final conformity of the JSF specification, the Struts / JSF integration tools have also emerged and have been widely used.
For more JSTL and JSF, please refer to:
Practical JSTL, Part 1 - Spielman; JSF Central - JSF resources; JAVASERVER FACES RESOURCES - JAMES HOLMES DOT COM;
0.9 XML language
Many objects provided by the Struts framework are provided by deploying an XML configuration file. Configuring a Java web application is also available through an XML file.
For more information on XML configuration files and Java web applications, please refer to:
Configuring Web Applications in The Java Web Tutorial;
About how to use an XML file in a normal Java application, you can refer to the Java API for XML Process in The Java Web Services Tutorial. The internal Struts framework fully uses this API, and Struts developers may not be used when developing their own applications.
0.9.1 Descriptor (Descriptor)
When the Java application uses an XML configuration file, the element is often used as a descriptor, and the application does not directly use the XML element. These elements are used to create and configure (or deploy) Java objects.
The Java Servlet platform deploys a servlet using an XML configuration file. The same Struts framework also uses the XML file to deploy the object used by the framework.
0.10 other layers (Layers)
The Struts framework provides a controller layer for web applications, developers can use some other standard techniques to provide a data access layer and a performance layer to cooperate with the controller. Common popular data access technology includes:
Enterprise Java Beans; JDBC; Object Relational Bridge;
The performance layer technology includes:
JavaServer Pages; XSL Transformations;
0.11 Jaas
The Struts framework can use many methods for user authentication and authorization, Struts1.1, and later versions support standard Java authentication and authorization services (JAAS). You can specify the security role between Action.
About JAAS, please refer to the Javasoft Product Page and Java Web Services Tutorial's Web Application Security Chapter