创建Web应用的配置文件
对于Struts应用,它的配置文件web.xml应该对ActionServlet类进行配置,此外,还应该声明Web应用所使用的Struts标签库,本例中声明使用了三个标签库: Struts Bean、Struts Html和Struts Logic标签库。例程1为web.xml的源代码。
例程1 web.xml创建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>
新闻热点
疑难解答