Struts2 环境配置

2018-07-13  本文已影响3人  tingshuo123

1. 导入架包

去官网下载核心架包,然后导入Web工程
下载地址http://struts.apache.org/download.cgi

核心架包

2.配置Struts2的核心控制器

Struts2的核心控制器本质就是注册一个过滤器,使用它,需要在Web工程的的 web.xml 中注册。
web.xml内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"/>
    <filter>
        <filter-name>Struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Structs2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
web.xml

3. 配置 struts.xml

在src目录下创建 struts.xml 文件,添加以下内容

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

<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="login" class="com.project.actions.LoginAction" method="execute">
            <result name="success">/success.jsp</result>
            <result name="fail">/test.html</result>
        </action>
    </package>
</struts>
上一篇 下一篇

猜你喜欢

热点阅读