亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

5. Configuring Applications

2019-11-18 11:29:53
字體:
來源:轉載
供稿:網友

5. Configuring applications

5.1 Overview

Before you can build an application, you need to lay a solid foundation. There are several setup tasks you need to perform before deploying your Struts application. These include components in the Struts configuration file and in the Web Application Deployment Descriptor.

5.2 The Struts configuration file

The Building Controller Components chapter covered writing the <form-bean> and <action-mapping> portions of the Struts configuration file. These elements usually play an important role in the development of a Struts application. The other elements in Struts configuration file tend to be static: you set them once and leave them alone.

These "static" configuration elements are:

  • <controller>
  • <message-resources>
  • <plug-in>
  • <data-sources>

5.2.1 Controller Configuration

The <controller> element allows you to configure the ActionServlet. Many of the controller parameters were PReviously defined by servlet initialization parameters in your web.xml file but have been moved to this section of struts-config.xml in order to allow different modules in the same web application to be configured differently. For full details on available parameters see the struts-config_1_2.dtd or the list below.

  • bufferSize - The size (in bytes) of the input buffer used when processing file uploads. [4096] (optional)
  • className - Classname of configuration bean. [org.apache.struts.config.ControllerConfig] (optional)
  • contentType - Default content type (and optional character encoding) to be set on each response. May be overridden by the Action, jsp, or other resource to which the request is forwarded. [text/Html] (optional)
  • forwardPattern - Replacement pattern defining how the "path" attribute of a <forward> element is mapped to a context-relative URL when it starts with a slash (and when the contextRelative property is false). This value may consist of any combination of the following:
    • $M - Replaced by the module prefix of this module.
    • $P - Replaced by the "path" attribute of the selected <forward> element.
    • $$ - Causes a literal dollar sign to be rendered.
    • $x - (Where "x" is any character not defined above) Silently swallowed, reserved for future use.
    If not specified, the default forwardPattern is consistent with the previous behavior of forwards. [$M$P] (optional)
  • inputForward - Set to true if you want the input attribute of <action> elements to be the name of a local or global ActionForward, which will then be used to calculate the ultimate URL. Set to false to treat the input parameter of <action> elements as a module-relative path to the resource to be used as the input form. [false] (optional)
  • locale - Set to true if you want a Locale object stored in the user's session if not already present. [true] (optional)
  • maxFileSize - The maximum size (in bytes) of a file to be accepted as a file upload. Can be eXPressed as a number followed by a "K", "M", or "G", which are interpreted to mean kilobytes, megabytes, or gigabytes, respectively. [250M] (optional)
  • multipartClass - The fully qualified java class name of the multipart request handler class to be used with this module. [org.apache.struts.upload.CommonsMultipartRequestHandler] (optional)
  • nocache - Set to true if you want the controller to add HTTP headers for defeating caching to every response from this module. [false] (optional)
  • pagePattern - Replacement pattern defining how the page attribute of custom tags using it is mapped to a context-relative URL of the corresponding resource. This value may consist of any combination of the following:
    • $M - Replaced by the module prefix of this module.
    • $P - Replaced by the "path" attribute of the selected <forward> element.
    • $$ - Causes a literal dollar sign to be rendered.
    • $x - (Where "x" is any character not defined above) Silently swallowed, reserved for future use.
    If not specified, the default pagePattern is consistent with the previous behavior of URL calculation. [$M$P] (optional)
  • processorClass - The fully qualified Java class name of the RequestProcessor subclass to be used with this module. [org.apache.struts.action.RequestProcessor] (optional)
  • tempDir - Temporary working Directory to use when processing file uploads. [{the directory provided by the servlet container}]

This example uses the default values for several controller parameters. If you only want default behavior you can omit the controller section altogether.

<controller    processorClass="org.apache.struts.action.RequestProcessor"       contentType="text/html"/>;

5.2.2 Message Resources Configuration

Struts has built in support for internationalization (I18N). You can define one or more <message-resources> elements for your webapp; modules can define their own resource bundles. Different bundles can be used simultaneously in your application, the 'key' attribute is used to specify the desired bundle.

  • className - Classname of configuration bean. [org.apache.struts.config.MessageResourcesConfig] (optional)
  • factory - Classname of MessageResourcesFactory. [org.apache.struts.util.PropertyMessageResourcesFactory] (optional)
  • key - ServletContext attribute key to store this bundle. [org.apache.struts.action.MESSAGE] (optional)
  • null - Set to false to display missing resource keys in your application like '???keyname???' instead of null. [true] (optional)
  • parameter - Name of the resource bundle. (required)

Example configuration:

<message-resources    parameter="MyWebAppResources"         null="false" />

This would set up a message resource bundle provided in the file MyWebAppResources.properties under the default key. Missing resource keys would be displayed as '???keyname???'.

5.2.3 PlugIn Configuration

Struts PlugIns are configured using the <plug-in> element within the Struts configuration file. This element has only one valid attribute, 'className', which is the fully qualified name of the Java class which implements the org.apache.struts.action.PlugIn interface.

For PlugIns that require configuration themselves, the nested <set-property> element is available.

This is an example using the Tiles plugin:

<plug-in className="org.apache.struts.tiles.TilesPlugin">    <set-property        property="definitions-config"           value="/WEB-INF/tiles-defs.xml"/></plug-in>

5.2.4 Data Source Configuration

Besides the objects related to defining ActionMappings, the Struts configuration may contain elements that create other useful objects.

The <data-sources> section can be used to specify a collection of DataSources [javax.sql.DataSource] for the use of your application. Typically, a DataSource represents a connection pool to a database or other persistent store. As a convenience, the Struts DataSource manager can be used to instantiate whatever standard pool your application may need. Of course, if your persistence layer provides for its own connections, then you do not need to specify a data-sources element.

Since DataSource implementations vary in what properties need to be set, unlike other Struts configuration elements, the <data-source> element does not pre-define a slate of properties. Instead, the generic <set-property> feature is used to set whatever properties your implementation may require. Typically, these settings would include:

  • A driver class name
  • A url to access the driver
  • A description

And other sundry properties.

<data-source type="org.apache.commons.dbcp.BasicDataSource"><!-- ... set-property elements ... --></data-source>

Since Struts 1.2.0, the GenericDataSource has been removed, and it is recommended that you use the Commons BasicDataSource or other DataSource implementations instead. In practice, if you need to use the DataSource manager, you should use whatever DataSource implementation works best with your container or database.

For examples of specifying a <data-sources> element and using the DataSource with an Action, see the Accessing a Database HowTo.

5.3 Configuring your application for modules

Very little is required in order to start taking advantage of the Struts module feature. Just go through the following steps:

  1. Prepare a configuration file for each module.
  2. Inform the controller of your module.
  3. Use Actions to refer to your pages.

5.3.1 Module Configuration Files

Back in Struts 1.0, a few "boot-strap" options were placed in the web.xml file, and the bulk of the configuration was done in a single struts-config.xml file. Obviously, this wasn't ideal for a team environment, since multiple users had to share the same configuration file.

Since Struts 1.1, you have two options: you can list multiple struts-config files as a comma-delimited list, or you can subdivide a larger application into modules.

With the advent of modules, a given module has its own configuration file. This means each team (each module would presumably be developed by a single team) has their own configuration file, and there should be a lot less contention when trying to modify it.

5.3.2 Informing the Controller

Since Struts 1.0, you listed your configuration file as an initialization parameter to the action servlet in web.xml. This is still done since Struts 1.1, but the parameter can be extended. In order to tell the Struts machinery about your different modules, you specify multiple 'config' initialization parameters, with a slight twist. You'll still use 'config' to tell the ActionServlet about your "default" module, however, for each additional module, you will list an initialization parameter named "config/module", where module is the name of your module (this gets used when determining which URIs fall under a given module, so choose something meaningful!). For example:

    ...    <init-param>        <param-name>config</param-name>        <param-value>/WEB-INF/conf/struts-default.xml</param-value>    </init-param>    <init-param>        <param-name>config/module1</param-name>        <param-value>/WEB-INF/conf/struts-module1.xml</param-value>    </init-param>    ...

Here we have two modules. One happens to be the "default" module, which has no "/module" in its name, and the other one named "module1" (config/module1). The controller is configured to find the respective configuration files under /WEB-INF/conf/ (which is the recommended place to put all configuration files). Pretty simple!

(The struts-default.xml would be equivalent to what most folks call struts-config.xml. I just like the symmetry of having all my Struts module configuration files being named struts-modulename.xml)

If you'd like to vary where the pages for each module are stored, see the forwardPattern setting for the Controller.

5.3.3 Switching Modules

There are three approaches for switching from one module to another. You can use the built-in org.apache.struts.actions.SwitchAction, you can use a <forward> (global or local) and specify the contextRelative attribute with a value of true, or you can specify the "module" parameter as part of any of the Struts hyperlink tags (Include, Img, Link, Rewrite, or Forward).

You can use org.apache.struts.actions.SwitchAction like so:

    ...    <action-mappings>    <action path="/toModule"    type="org.apache.struts.actions.SwitchAction"/>    ...    </action-mappings>    ...

Now, to change to ModuleB, we would use a URI like this:

    http://localhost:8080/toModule.do?prefix=/moduleB&page=/index.do    

If you are using the "default" module as well as "named" modules (like "/moduleB"), you can switch back to the "default" module with a URI like this:

    http://localhost:8080/toModule.do?prefix=&page=/index.do    

Here's an example of a global forward:

<global-forwards>    <forward       name="toModuleB"        contextRelative="true"                   path="/moduleB/index.do"               redirect="true"/>   ...</global-forwards>

You could do the same thing with a local forward declared in an ActionMapping:

   <action-mappings>   <action ... >       <forward       name="sUCcess"           contextRelative="true"                      path="/moduleB/index.do"                  redirect="true"/>   </action>   ...   </action-mappings>   

Or, you can use org.apache.struts.actions.SwitchAction:

   <action-mappings>   <action path="/toModule"           type="org.apache.struts.actions.SwitchAction"/>   ...   </action-mappings>   

Now, to change to ModuleB, we would use a URI like this:

   http://localhost:8080/toModule.do?prefix=/moduleB&page=/index.do    

Using the module parameter with a hyperlink tag is even simplier:

    <html:link module="moduleB" path="/index.do"/>    

That's all there is to it! Happy module-switching!

5.4 The Web Application Deployment Descriptor

The final step in setting up the application is to configure the application deployment descriptor (stored in file WEB-INF/web.xml) to include all the Struts components that are required. Using the deployment descriptor for the example application as a guide, we see that the following entries need to be created or modified.

5.4.1 Configure the ActionServlet Instance

Add an entry defining the action servlet itself, along with the appropriate initialization parameters. Such an entry might look like this:

<servlet>    <servlet-name>action</servlet-name>    <servlet-class>        org.apache.struts.action.ActionServlet    </servlet-class>    <init-param>        <param-name>config</param-name>        <param-value>         /WEB-INF/struts-config.xml        </param-value>    </init-param>    <load-on-startup>1</load-on-startup></servlet>

The initialization parameters supported by the action servlet are described below. (You can also find these details in the Javadocs for the ActionServlet class.) Square brackets describe the default values that are assumed if you do not provide a value for that initialization parameter.

  • config - Context-relative path to the XML resource containing the configuration information for the default module. This may also be a comma-delimited list of configuration files. Each file is loaded in turn, and its objects are appended to the internal data structure. [/WEB-INF/struts-config.xml].


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美成人激情图片网| 亚洲天堂网在线观看| 97国产真实伦对白精彩视频8| 日韩精品在线免费观看视频| 精品一区二区三区四区在线| 精品久久久91| 欧美小视频在线| 日本精品视频在线播放| 黄色成人av网| 日韩欧美亚洲一二三区| 亚洲精品美女网站| 久久九九有精品国产23| 精品偷拍各种wc美女嘘嘘| 国产精品三级美女白浆呻吟| 91性高湖久久久久久久久_久久99| 欧美午夜精品久久久久久浪潮| 亚洲福利在线播放| 亚洲天堂网站在线观看视频| 欧美日韩激情网| 国产午夜精品全部视频播放| 国产亚洲精品美女久久久久| 欧美激情视频在线观看| 日韩在线视频免费观看| 亚洲欧美激情视频| 日韩av网址在线| 中文字幕少妇一区二区三区| 日韩视频欧美视频| 日韩最新中文字幕电影免费看| 一道本无吗dⅴd在线播放一区| 久久久欧美一区二区| 国产精品观看在线亚洲人成网| 国产精品亚洲片夜色在线| 国产成人精彩在线视频九色| 亚洲精品久久久久中文字幕欢迎你| 久久精品亚洲精品| 日韩精品在线第一页| 国产精品免费网站| 91精品国产99| 亚洲影影院av| 成人一区二区电影| 久久99国产精品自在自在app| 2020欧美日韩在线视频| 亚洲天堂av综合网| 日韩电影大片中文字幕| 在线亚洲国产精品网| 国产精品jizz在线观看麻豆| 精品视频偷偷看在线观看| 欧美成人激情视频| 亚洲淫片在线视频| 久久精品视频免费播放| 日韩中文字幕不卡视频| 免费av在线一区| 亚洲成人精品在线| 久久精品美女视频网站| 欧美剧在线观看| 欧美成人免费一级人片100| 欧美成人三级视频网站| 在线视频欧美日韩精品| 日韩大片在线观看视频| 久久久人成影片一区二区三区| 日韩乱码在线视频| 亚洲第一中文字幕在线观看| 久久成人18免费网站| 亚洲jizzjizz日本少妇| 精品国内产的精品视频在线观看| 亚洲国产第一页| 国产精品美女免费视频| 在线看片第一页欧美| 在线观看国产精品91| 欧美大片欧美激情性色a∨久久| 国产精品日韩在线一区| 性夜试看影院91社区| 精品视频久久久久久| 色综合影院在线| 91av视频在线| 国产精品99久久久久久www| 国产精品爽黄69天堂a| 国产精品视频最多的网站| 久久人人爽人人爽人人片亚洲| 久久久久久亚洲精品中文字幕| 色妞欧美日韩在线| 亚洲最大av在线| 国产一区二区香蕉| 亚洲少妇中文在线| 538国产精品一区二区在线| 在线观看国产欧美| 亚洲天堂成人在线视频| 国产精品无码专区在线观看| 国产日韩欧美成人| 91久久久久久久久| 久久精品视频亚洲| 欧美在线亚洲在线| 尤物yw午夜国产精品视频| 日韩中文字幕欧美| 九九精品在线视频| 亚洲人成五月天| 欧美精品在线看| 午夜精品国产精品大乳美女| 日韩色av导航| 亚洲女人被黑人巨大进入al| 日韩女优在线播放| 中文字幕视频在线免费欧美日韩综合在线看| 中文字幕成人精品久久不卡| 亚洲自拍偷拍第一页| 国产精品美女无圣光视频| 91香蕉嫩草影院入口| 96国产粉嫩美女| 日韩av中文字幕在线免费观看| 亚洲第一av网| 亚洲人精选亚洲人成在线| 国产精品国产三级国产aⅴ9色| 91夜夜揉人人捏人人添红杏| 亚洲黄色www| 亚洲国产天堂网精品网站| 在线电影欧美日韩一区二区私密| 日韩成人在线播放| 亚洲另类图片色| 欧美自拍视频在线观看| 亚洲老板91色精品久久| 国产欧美日韩中文字幕| 色综合久久天天综线观看| 日韩av在线免费观看| 成人黄色在线观看| 亚洲va欧美va国产综合久久| 日韩高清电影免费观看完整版| 日韩电影中文 亚洲精品乱码| 91久久久久久久久久| 日韩精品视频在线观看免费| 91精品国产色综合久久不卡98| 亚洲成人免费在线视频| 欧美激情免费观看| 亚洲国语精品自产拍在线观看| 国产精品夜间视频香蕉| 国产丝袜高跟一区| 久久成人精品一区二区三区| 国产精品极品美女在线观看免费| 美女视频黄免费的亚洲男人天堂| 日韩福利视频在线观看| 亚洲国产日韩欧美综合久久| 欧美极品美女视频网站在线观看免费| 欧美人与性动交a欧美精品| 97av在线视频免费播放| 91精品久久久久久久久青青| 欧美性猛交xxxx偷拍洗澡| 亚洲二区中文字幕| 日韩av电影院| 国产区精品在线观看| 国产在线一区二区三区| 国产精品 欧美在线| 国产91精品黑色丝袜高跟鞋| 国产视频欧美视频| 欧美另类在线观看| 亚洲一区二区三区在线视频| 精品一区二区三区三区| 亚洲国产精品va在线| 国产精品日韩欧美综合| 日韩欧美有码在线| 91成人在线观看国产| 亚洲欧美国产日韩中文字幕| 成人综合国产精品| 中文字幕精品视频| 欧美午夜精品久久久久久浪潮| 欧美成人精品h版在线观看| 成人妇女淫片aaaa视频|