<script type="text/javascript"><!----></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script>
<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0714075272818912&amp;dt=1181221632546&amp;lmt=1181221632&amp;prev_fmts=120x90_0ads_al_s&amp;format=336x280_as&amp;output=html&amp;correlator=1181221632109&amp;url=http%3A%2F%2Fwww.roseindia.net%2Fstruts%2Funderstanding_struts_controller.shtml&amp;color_bg=FFFFFF&amp;color_text=000080&amp;color_link=000080&amp;color_url=000080&amp;color_border=FFFFFF&amp;ad_type=text_image&amp;ref=http%3A%2F%2Fwww.roseindia.net%2Fstruts%2Funderstandingstruts_action_class.shtml&amp;cc=1382&amp;flash=9&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=15&amp;u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency=""></iframe>
In this section I will describe you the Controller part of the Struts Framework. I will show you how to configure the struts-config.xml file to map the request to some destination servlet or jsp file.
The class org.apache.struts.action.ActionServlet is the heart of the Struts Framework. It is the Controller part of the Struts Framework. ActionServlet is configured as Servlet in the web.xml file as shown in the following code snippets.
<!-- Standard Action Servlet Configuration (with debugging) --> <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> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> |
This servlet is responsible for handing all the request for the Struts Framework, user can map the specific pattern of request to the ActionServlet. <servlet-mapping> tag in the web.xml file specifies the url pattern to be handled by the servlet. By default it is *.do, but it can be changed to anything. Following code form the web.xml file shows the mapping.
<!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> |
<script type="text/javascript"><!----></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script>
<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0714075272818912&amp;dt=1181221632578&amp;lmt=1181221632&amp;prev_fmts=120x90_0ads_al_s%2C336x280_as&amp;format=336x280_as&amp;output=html&amp;correlator=1181221632109&amp;url=http%3A%2F%2Fwww.roseindia.net%2Fstruts%2Funderstanding_struts_controller.shtml&amp;color_bg=FFFFFF&amp;color_text=000080&amp;color_link=000080&amp;color_url=000080&amp;color_border=FFFFFF&amp;ad_type=text_image&amp;ref=http%3A%2F%2Fwww.roseindia.net%2Fstruts%2Funderstandingstruts_action_class.shtml&amp;cc=1382&amp;flash=9&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=15&amp;u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency=""></iframe>
The above mapping maps all the requests ending with .do to the ActionServlet. ActionServlet uses the configuration defined in struts-config.xml file to decide the destination of the request. Action Mapping Definitions (described below) is used to map any action. For this lesson we will create Welcome.jsp file and map the "Welcome.do" request to this page.
Welcome.jsp
<%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <html:html locale="true"> <head> <title><bean:message key="welcome.title"/></title> <html:base/> </head> <body bgcolor="white"> <h3><bean:message key="welcome.heading"/></h3> <p><bean:message key="welcome.message"/></p> </body> </html:html>
|
Forwarding the Welcome.do request to Welcome.jsp
The "Action Mapping Definitions" is the most important part in the struts-config.xml. This section takes a form defined in the "Form Bean Definitions" section and maps it to an action class.
Following code under the <action-mappings> tag is used to forward the request to the Welcome.jsp.
<action path="/Welcome" forward="/pages/Welcome.jsp"/>
|
To call this Welcome.jsp file we will use the following code.
<html:link page="/Welcome.do">First Request to the controller</html:link>
|
Once the use clicks on on First Request to the controller link on the index page, request (for Welcome.do) is sent to the Controller and the controller forwards the request to Welcome.jsp. The content of Welcome.jsp is displayed to the user.
分享到:
相关推荐
**Struts2** 是一个基于 **MVC** (Model-View-Controller)设计模式的Java Web应用程序框架,它是由Apache软件基金会维护的一个开源项目。Struts2不仅继承了原始Struts框架的优点,而且在其基础上进行了大量的改进...
《理解与应用控制器局域网通信协议:理论与实践》是一本深入探讨CAN(Controller Area Network)总线技术的专业书籍,由Marco Di Natale、Haibo Zeng、Paolo Giusto和Arkadeb Ghosal等专家合著。CAN总线是一种在汽车...
Controller Area Network (CAN) 是一种广泛应用的现场总线协议,主要设计用于汽车电子系统,但其可靠性和效率也使其在工业自动化、医疗设备、航空航天等多个领域得到广泛采用。本篇文章将深入探讨CAN 2.0b标准,以及...
Numerous books have been written about C. They usually offer a broad ...That higher level of understanding for C can only be achieved with a solid understanding of pointers and the management of memory.
根据提供的文件信息,可以得知“Understanding Understanding”是由Heinz von Foerster所著的一本书籍,该书以“Essays on Cybernetics and Cognition”为副标题,涉及的领域是认知理论与人工智能。书名中的...
Understanding zigbee rf4ce
Understanding .NET - A Tutorial and Analysis Understanding .NET - A Tutorial and Analysis Understanding .NET - A Tutorial and Analysis
《Understanding Digital Signal Processing》是一本关于数字信号处理(Digital Signal Processing,简称DSP)的经典教材,主要由***ons撰写。该书是前版的扩展,旨在帮助初学者理解数字信号处理的理论,并为在职...
Practical Apache Struts 2 Web 2.0 Projects shows you how to capitalize upon these new features to build next–generation web ...Gain an in–depth understanding of the Struts framework...
SIP: Understanding the Session Initiation Protocol, Fourth Edition 英文原版,第4版
4. 《UnderStanding The Linux Kernel 3rd Edition V413HAV.pdf》:这正是标题中提到的《理解Linux内核》第三版,书中详尽介绍了Linux 2.6.x版本内核的设计和实现,包括调度程序、内存管理、文件系统、网络协议栈等...
Understanding ECMAScript 6 中文版
有需要的没有积分的,可以发邮件h5ru@qq.com,我发给你。 ELF 格式解析,基于ELF规范v1.2版本。 版权方为:E-mail: fion2009.z@gmail.com 备用邮箱及MSN:fyzhao2004@hotmail.com 作者赵凤阳 现就职于爱立信(Ericsson...
Understanding The Linux Kernel 完美组合 Understanding The Linux Kernel 完美组合 Understanding The Linux Kernel 完美组合
Understanding Maple 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
"Understanding FACTS"是电力电子在电力系统应用的经典文献,对于理解灵活交流输电系统(Flexible AC Transmission Systems,简称FACTS)具有重要帮助。FACTS是指一系列用于提高电力传输效率、可靠性和控制性能的...
Understanding and Eliminating EMI