搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )

一.Struts介绍

Struts是Apache软件基金会(ASF)赞助的一个开源项目。它最初是jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目。它通过采用JavaServlet/JSP技术,实现了基于JavaEEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品。

二.搭建环境(使用Intellij IDEA+maven+struts2)

1.创建maven+struts2项目
2.添加配置文件,自动下载必要jar包

    org.apache.struts
    struts2-core
    2.5.10.1

3.webxml中引入struts核心功能——配置过滤器
4.开发action
5.配置action——src/struts.xml
1.创建maven+struts2项目步骤:

1).创建Maven项目:maven快速入门

  • 搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第1张图片

2).设置Groupld和Artfactld名称

  • 搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第2张图片
2.添加配置文件,自动下载必要jar包

commons-fileupload-1.2.2.jar 【文件上传相关包】
commons-io-2.0.1.jar
struts2-core-2.3.4.1.jar 【struts2核心功能包】
ognl-3.0.5.jar 【Ognl表达式功能支持表】
commons-lang3-3.1.jar 【struts对java.lang包的扩展】
freemarker-2.3.19.jar 【struts的标签模板库jar文件】
javassist-3.11.0.GA.jar 【struts对字节码的处理相关jar】
配置文件引入


   org.apache.struts
   struts2-core
   2.5.10.1

  • 搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第3张图片

3.webxml中引入struts核心功能——配置过滤器

web.xml



  Archetype Created Web Application
  
  
    struts2
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  
  
    struts2
    /*
  
  
    index.jsp
  


搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第4张图片
4.开发action

LoginAction.java

package com.huan.struts.action;

/**
 * Created by 马欢欢 on 2017/6/19.
 */
public class LoginAction {
    public String success(){
        System.out.println("成功访问action,请求正在处理中");
        System.out.println("调用service");
        return "success";
    }
}

success.jsp

<%--
  Created by IntelliJ IDEA.
  User: 马欢欢
  Date: 2017/6/19
  Time: 21:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    success成功跳转到该页面





5.配置action——src/struts.xml

struts2.xml






    
        
            success.jsp
        
    

搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第5张图片
搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第6张图片
启动成功
访问成功
搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第7张图片
成功访问
控制台打印
搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 )_第8张图片

你可能感兴趣的:(搭建struts2 项目开发环境——(使用Intellij IDEA+Maven+struts2 ))