創(chuàng)建Web應(yīng)用的配置文件
對于Struts應(yīng)用,它的配置文件web.xml應(yīng)該對ActionServlet類進行配置,此外,還應(yīng)該聲明Web應(yīng)用所使用的Struts標(biāo)簽庫,本例中聲明使用了三個標(biāo)簽庫: Struts Bean、Struts Html和Struts Logic標(biāo)簽庫。例程1為web.xml的源代碼。
例程1 web.xml創(chuàng)建Struts框架的配置文件
正如前面提及的,Struts框架答應(yīng)把應(yīng)用劃分成多個組件,提高開發(fā)速度。而Struts框架的配置文件struts-config.xml可以把這些組件組裝起來,決定如何使用它們。例程2是helloapp應(yīng)用的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>
新聞熱點
疑難解答