Struts1.x 文件配置完整小例子

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name />  
 <!--注册Struts中心控制器--> 
  <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>3</param-value>
    </init-param>
    
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    
    <load-on-startup>0</load-on-startup><!--服务器启动就初始化 0表示最先初始化  -->
    
  </servlet>
   
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern><!--表示对所有的do请求都进行初始化  -->
  </servlet-mapping>
  

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
  <form-beans >
    <form-bean name="HelloForm" type="com.yourcompany.struts.form.HelloForm" />
  </form-beans>
	<!--struts-config.xml文件中<form-beans>和<action-mappings>的顺序不能变,有DTD约束规定。  -->

  <global-exceptions />
  <global-forwards />

  <action-mappings >
  <!-- input 验证失败时的转发路径 -->
  <!-- path请求访问的Action的路径 -->
  <!-- <forward>定义请求转发的路径 -->
  <!--	path指明调用者(JSP)能通过中心控制器ActionServlet找到该Action  -->
    <action
    	 path="/HelloWord"
    	 type="com.yourcompany.struts.action.HelloAction"
    	 name="HelloForm"
         scope="request" 
         validate="true"  
     	 input="/hello.jsp">
      <forward name="SayHello" path="/hello.jsp" />
    </action>
  </action-mappings>
  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>


你可能感兴趣的:(web.xml,Struts1.X)