Struts Quick Learning Guide 01 (internal training materials) - Most material comes from "Programming Jakarta Struts"

xiaoxiao2021-03-06  39

1. Introduction to Struts

Struts is a technology framework, written by Craig R. McClanahan, and donated to ASF in 2000. Currently, there are many organizations and individuals to participate in the development of the Struts framework, so that Struts has grown high-speed growth, while using Struts development There are more and more, making it the actual standard of the VC part in the web application MVC mode.

1.1 Web Technology History

1.1.1 CGI

In history, CGI (Common Gateway Interface) is a technology that is the earliest use of different platforms, different web server write plugins to meet the needs of applications through web methods. At that time, the popular manner included NSAPI / ISAPI, using Perl to write CGI programs. The biggest problem with CGI is the problem of thread concurrency. At that time, the feeling of the CGI was slow, the main reason was that the CGI written by the application did not consider multithreading.

1.1.2 servlet

As a cross-platform language server-side technology, it is highly attractive, and the application of servlet development is used. It does not need to consider the problem of platform, multi-thread, etc., so that developers focus on business logic, great liberation. Productivity. However, embed HTML in servlet is undoubtedly a nightmare of developers. Compared to Microsoft ASPs in the same time, servlet is not compliminated in development efficiency.

1.1.3 Java Server Pages

JSP has a large extent to the ASP idea, making it easy to develop server-side applications using Java language, while Java and later cross-platform, security, ease of use, and developers High wage j makes JSP to gradually occupy the mainstream position in Web server application development.

2. Struts installation

Struts As a J2EE framework, strut is easy to combine your web app, you just need to make the following steps:

1, under the struts1.1 binary compression package, extract the compressed package to the% struts_home% directory, the directory structure is as shown as shown in:

2, build your standard web application, the so-called standard application refers to a web-info directory in the root of the web application, and there is a Classes, a lib directory, and a web.xml file under Web-INF. This article is subsequently assumes that your web application is in the% Web_root% directory.

3. Put all files to% web_root% / Web-INF / LIB in% struts_home% / lib.

4, configure% web_root% / web-inf / class / web.xml to meet the Struts needs, as follows:

1. Mapping an ActionServlet in the configuration file, ActionServlet is used to accept all visitor's request. In Struts applications, all requests for applications will be individually controlled by Web Server to ActionServlet, allocate, ActionServlets can be seen as the core, hub of the Struts framework.

controller

org.apache.struts.Action.ActionServlet

2. Configure the servlet mapping. You can access the web application's extension to the specific processing of the SERVLET, for example, to the ActionServlet processing by servlet mapping. For example, all requests for .do to the extended page.

controller

org.apache.struts.Action.ActionServlet

controller

*. do

Alternatively, mapping can be performed in the following manner, which hands all access requests for / Action / directory to ActionServlet processing.

controller

org.apache.struts.Action.ActionServlet

controller

> / action / *

3, configure the initialization parameters of the ActionServlet, Struts1.1 has some specified initialization parameters, used to indicate the configuration files required for the Struts application, the DEBUG level, etc.

controller

org.apache.struts.Action.ActionServlet

config

/web-inf/struts-config.xml

Host

localhost

port

7001

controller

*. do

The initialization parameter is configured with , configures the name-value-pair method, one corresponding to one , initialization parameters can be arbitrarily defined, such as Host, Port, but there are some in struts1 . 1 is of particular meaning, listed below:

Table 2-1. Initialization parameter names used in Struts1.1 Meaning / Defaults Config indicates the configuration file location of the Struts application in a relative path. If not set, the default value is /Web-inf/Struts-Config.xml. Config / SUB1 specifies the profile location of the sub-application in a relative path, in general, rarely use the child application, not described here. Debug Sets the Debug level of the servlet, the level of controlling logging. Default is 0, logging relatively least least log information. Detail Setting DiGester's debug level, Digester is a framework used by the STRUTS framework to parse the XML configuration file, and you can view the parsing log of different detailed levels through this setting. Default is 0, logging relatively least least log information.

转载请注明原文地址:https://www.9cbs.com/read-65286.html

New Post(0)