struts2.5.x环境配置

  • 开发环境
    Myeclipse2017 / Tomcat8.5 / Struts2.5.12
  • jar包导入
1.  commons-fileupload-1.3.3.jar  
2.  commons-io-2.4.jar  
3.  commons-lang3-3.3.6.jar  
4.  commons-logging-1.1.3.jar  
5.  freemarker-2.3.23.jar  
6.  javassist-3.20.0-GA.jar  
7.  log4j-api-2.5.jar  
8.  log4j-core-2.8.2.jar
9.  ognl-3.1.12.jar  
10. struts2-core-2.5.2.jar  
  • 在web.xml中编写配置文件
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  • 写struts2.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="action" extends="struts-default">
    <!-- 
        @package        package is a unit to group action which is similar to the package in Java
                            package can be extended and overridden.
        @attribute        name          it is required for distinction.
                            extends     inherits other package
                            namespace   URL of the web project
                            abstract        an empty package
     -->
        <action name="hello" class="action.action1" >
        <!--  
        @action     action is a action that you can visit the JSP page by the action name
        @attribute        name      it is require for distinction
                            flush       Default is true.flush the write at the end of the action or not.
                            ignoreContextParams when the action is invoked ,the parameter is included.
                            var         Push the value into Value Stack
        -->
            <result name="success">/hello.jsp</result>
            <!-- 
            @result         Result is the definition of action
            @attribute  name        it has default name "dispatcher".It corresponds to the function
                                       of the JavaBean.
             -->
        </action>
    </package>
    
</struts>
  • 写java类实现execute()方法
package action;

public class action1 {
    public String  execute() {
        System.out.println("action1");
        return "success";
    }
}
  • 对应的jsp页面(只是简单显示而已)命名要和struts.xml中的result中的值对应,通过浏览器访问。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述 什么是Struts2的框架Struts2是Struts1的下一代产品,是在 struts1和WebWork的...
    inke阅读 2,276评论 0 50
  • 本文包括: 1、Struts 2 概述2、Struts 2 快速入门3、Struts 2 的执行流程4、配置 st...
    廖少少阅读 2,998评论 3 13
  • 概述 Struts就是基于mvc模式的框架!(struts其实也是servlet封装,提高开发效率!) Strut...
    奋斗的老王阅读 2,986评论 0 51
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,764评论 18 399
  • strust2框架来历简介: WebWork是由OpenSymphony组织开发的,致力于组件化和代码重用的J2E...
    清枫_小天阅读 8,924评论 4 26