美文网首页
Struts2 环境配置

Struts2 环境配置

作者: tingshuo123 | 来源:发表于2018-07-13 23:04 被阅读3次

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>

相关文章

网友评论

      本文标题:Struts2 环境配置

      本文链接:https://www.haomeiwen.com/subject/ddmrpftx.html