JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JSP技术--STRUTS  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
Introduction of Struts
作者:     文章来源:
访问次数:92次     加入时间:2007年03月29日
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.
JSP虚拟主机 | JSP空间 | JSP主机 | JSP双线虚拟主机 | JAVA空间 | JAVA虚拟主机 | 虚拟服务器 | JSP 虚拟服务器 | VPS
Virtual Private Server | JAVA虚拟服务器 | VM服务器 | VHOST | 虚拟操作系统 | JSP论坛 | JAVA论坛 | JSP站点论坛
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号