分享
 
 
 

IntroductionofStruts

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

Hi,Every one.This is article is introdUCe STRUTS framework which I communicate with my colleagues.

an Introduction to Struts Framework

1. Start to Struts Framework

M-V-C (Model-View-Controller)

Just a Software Design Pattern, You can use any technology to implement it if you want to, Struts Framework is just one way Implement, But it is very good.

Model: Model is the main body of the Application, It stand for Business Data and Business Logic. One Model can support data to more View to reuse. So it let Application Reusable.

View: View is take account for Interact with the User.(UI)Just user interface .It display the relevant data to the user, Also receive the data from the user. But it won’t do any Business Process.

Controller: Control receive user’s input, then invoke Model and View to perform the user’s request.

Struts use what component to implement the M-V-C ?

Model: JavaBean and EJB( if the large Application).

View: jsp (use Struts taglib and Customize taglib), ActionForm Bean.(Like the common Bean, But have reset() and Validate() method.)

Controller: ActionServlet , Action

Struts Configure File: Struts-config.XML

2. configure Struts Application. Model, View, Controller.

Struts in focus on the Controller’s Design, It take the Servlet part into FormBean and ActionServlet. Also add Servlet API:Incude Action, Actionform, Action Mapping.

Every FormBean need extends from ActionForm Class.FormBean is encapsulation of the web request. It support the data to the ActionBean. For further process.

The core of the Struts is ActionServlet,And the Core of the ActionServlet is Struts-config.xml,So if you master the Struts-config.xml you already master Struts.

Web.xml:

1,Configure ActionServlet(only one),let it can receive the Application’s request.

<servlet>

<servlet-name>action</servlat-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

2,configure the init-param,set it to this format: <param-name><param-value>

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-confg.xml</param-value>

</init-param>

3,<taglib>use struts’s taglib you need configureinclude:

<taglib>

<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

<taglib-location>/WEB-INF/struts- bean.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-Html.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-html.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

<taglib-location>/WEB-INF/struts- logic.tld</taglib-location>

</taglib>

Struts-config.xml:

1. Every part’s configure specifiction in Struts-config.xml all depend on DTD file.The DTD file info is @ the File header.So read DTD is the best start way to configure the Struts-config.xml .Just as:

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

The different edition will get the different property .

2. The parameter’s order in Struts-config.xml is predefined,So you need put the element in the correct palce, But System will give you’re a template based on the DTD file.

Commonly include below list::

(1) data-sources: Configure the Data-source. Then you can get it in program,So you only need define it once, For easy maintenance.

(2) form-bean :Configure the Formbean which will transfer the data to the Action

(3) global-forwards :Configure the global-forward.The application will first find forward from <action> config,If not find,then find it from here.

(4) action-mapping :Configure the action,Let Container know how to handle the request.

In <action>,there are some property:

1.Name -------specify the corresponding actionform,This must had defined in <form-bean>

2.Input ----------specify the path,If there have exception occur then forward to this path,commonly it is the JSP file which you submit your info o the server.

3.path --------required,unique,specify the action,corresponding with the request,start with “/” if the request is http://localhost:8080/category1/abc.do,then the path is :”/abc”

4.Scope ------- default value is “session”.This specify the form’s life domain.

5.Type ---------required,extends from or.apache.struts.action.Action class’s fullname path java Class name.Just your Business logic process class.

6.Validate ----------default vale is true,It’s Boolean.Specify if the formBean’s validate() method need invoke.

7.Paramater --------commonly use with other component,Just like Forward Action or DispatchAction

(5) message-resource :Configure the message-resource file,Your can use it to realize Internationalization. Comonly use <Bean:message key=”msgKey”/>

The more important thing is if you modify the Struts-config.xml file,Then you need to restart application to let it have effect.

The Struts framework’s Controller component

The main component of the Struts Framework act as Controller is:

ActionServlet Component:just as Central controller of the Struts Framework.

RequestProcessor Component: Act as request processor for the every module.

Action Component: Take account for process one particular Business.

3. about Struts Taglib

There are so many tag in Struts,Below is some example,But I think if you need use,you can refer from any book which introduce the TagLib of the Struts.

<html:errors> this tag will display the Error info other component produce in Struts Framework.

<html:form> use to create HTML form.Can get form relevant with the corresponding ActionFormBean.

<html:text> use to create textbox in the Form.

<bean:message> use to output the locale text file.Just message-resource file.

<bean:write> use to output the JavaBean Property’s value.

<logic:present> use to determine if the specify JavaBean’s exist in the particular scope.

And so on……….

4. struts Framework integrated with EJB and Web Services.

Ok,think about you need more complex logic,then you need manage your session and the transaction,you need manage your DB’s connection and more,You will take the EJB to help you to resolve this problem.进入讨论组讨论。

(出处:http://www.knowsky.com)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有