选择显示字体大小

创建web应用和struts框架的配置文件

创建web应用的配置文件

对于struts应用,它的配置文件web.xml应该对actionservlet类进行配置,此外,还应该声明web应用所使用的struts标签库,本例中声明使用了三个标签库: struts bean、struts htmlstruts logic标签库。例程1为web.xml的源代码。

例程1 web.xml

<?xml version="1.0" encoding="utf-8"?>

<!doctype web-app

public "-//sun microsystems, inc.//dtd web application 2.2//en"

"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<display-name>helloapp struts application</display-name>

<!-- standard action servlet configuration -->

<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>2</load-on-startup>

</servlet>

<!-- standard action servlet mapping -->

<servlet-mapping>

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

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

</servlet-mapping>

<!-- the usual welcome file list -->

<welcome-file-list>

<welcome-file>hello.jsp</welcome-file>

</welcome-file-list>

<!-- struts tag library descriptors -->

<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>

</web-app>

创建struts框架的配置文件

正如前面提及的,struts框架允许把应用划分成多个组件,提高开发速度。而struts框架的配置文件struts-config.xml可以把这些组件组装起来,决定如何使用它们。例程2是helloapp应用的struts-config.xml文件的源代码。

例程2  struts-config.xml<?xml version="1.0" encoding="iso-8859-1" ?><!doctype struts-config public"-//apache software foundation//dtd struts configuration 1.1//en""http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><!--this is the struts configuration file 

for the "hello!" sample application--><struts-config><!-- ======== form bean definitions ==================== --> <form-beans> <form-bean name="helloform" type="hello.helloform"/> </form-beans><!-- ========== action mapping definitions =================== --> <action-mappings> <!-- say hello! --> <action path = "/helloworld" type = "hello.helloaction" name = "helloform" scope = "request" validate = "true" input = "/hello.jsp" > <forward name="sayhello" path="/hello.jsp" /> </action> </action-mappings> <!-- ========== message resources definitions ================ --> <message-resources parameter="hello.application"/></struts-config>


以上代码对helloapp应用的helloform、helloaction和消息资源文件进行了配置,首先通过元素配置了一个actionform bean,名叫helloform,它对应的类为hello.helloform:



接着通过元素配置了一个action组件: 
<action    path      = "/helloworld"          type      = "hello.helloaction"          name     = "helloform"          scope     = "request"          validate   = "true"             input     = "/hello.jsp"><forward name="sayhello" path="/hello.jsp" /></action>

元素的path属性指定请求访问action的路径,type属性指定action的完整类名,name属性指定需要传递给action的actionform bean,scope属性指定actionform bean的存放范围,validate属性指定是否执行表单验证,input属性指定当表单验证失败时的转发路径。元素还包含一个子元素,它定义了一个请求转发路径。

本例中的 元素配置了helloaction组件,对应的类为hello.helloaction,请求访问路径为"helloworld",当action类被调用时,struts框架应该把已经包含表单数据的helloform bean传给它。helloform bean存放在request范围内,并且在调用action类之前,应该进行表单验证。如果表单验证失败,请求将被转发到接收用户输入的网页hello.jsp,让用户纠正错误。

struts-config.xml文件最后通过元素定义了一个resource bundle:元素的parameter属性指定resource bundle使用的消息资源文件。本例中parameter属性为"hello.application",表明消息资源文件名为"application.properties",它的存放路径为web-inf/classes/hello/application.properties。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons