【Struts2复习知识点一】-配置struts2环境

1.添加struts2支持包到lib目录下。

2.创建struts.xml文件并放到src目录下。

View Code 

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

<struts>
    <!-- 
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />

    <include file="example.xml"/>



    <package name="default" namespace="/" extends="struts-default">
        <default-action-ref name="index" />
        <action name="index">
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
        </action>
    </package>
     -->
     
     <!--即时加载-->
     <constant name="struts.devMode" value="true" />
     <package name="default" namespace="/" extends="struts-default">
        
        <action name="hello">
            <result>
                /Hello.jsp
            </result>
        </action>
    </package>
    <!-- Add packages here -->

</struts>


3.配置web.xml文件

View Code 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


4. 访问 http://localhost:8080/projectrname/hello 即可查看Hello.jsp

注意:tomcat安装路径不能有空格。负责启动报错。

你可能感兴趣的:(【Struts2复习知识点一】-配置struts2环境)