zoukankan      html  css  js  c++  java
  • [原创]java WEB学习笔记54:Struts2学习之路---概述,环境的搭建

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用

    内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系。

    本人互联网技术爱好者,互联网技术发烧友

    微博:伊直都在0221

    QQ:951226918

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    1.关于Struts2 

      1)Struts2 是一个用来开发 MVC 应用程序的框架. 它提供了 Web 应用程序开发过程中的一些常见问题的解决方案: 

      2)对来自用户的输入数据进行合法性验证

      3)统一的布局

      4)可扩展性

      5)国际化和本地化

      5)支持 Ajax

      6)表单的重复提交

      7)文件的上传下载

     

    2.Struts2 VS Struts1

      1)在体系结构方面更优秀

        ①类更少, 更高效:  在 Struts2 中无需使用 “ActionForm” 来封装请求参数. 

        ② 扩展更容易:  Struts2 通过拦截器完成了框架的大部分工作. 在 Struts2 中插入一个拦截器对象相当简便易行. 

      2)更容易测试: 即使不使用浏览器也可以对基于 Struts2 的应用进行测试

     

    3.从 Struts1 升级到 Struts2

      1)Struts2 从本质上讲已不是从 Struts1 扩展而来的, 说它是一个换了品牌标签的 WebWork 更合适

      2)从 Struts1 升级到 Struts2

        ① Struts1 里使用 ActionServlet 作为控制器; Struts2 使用了一个过滤器作为控制器

        ② Struts1 中每个 HTML 表单都对应一个 ActionForm 实例. Struts2 中, HTML 表单将被直接映射到一个 POJO.

        ③ Struts1 的验证逻辑编写在 ActionForm 中; Struts2 中的验证逻辑编写在 Action 中.

        ④ Struts1 中, Action 类必须继承 org.apache.struts.action.Action 类; Struts2 中任何一个 POJO 都可以是一个 Action 类

        ⑤ Struts2 在页面里使用 OGNL 来显示各种对象模型, 可以不再使用 EL 和 JSTL

    4.下载 Struts2

      1)打开浏览器输入 http://struts.apache.org/

      2)点击超链接 “Struts 2.3.x”, 打开下载页面

      3)点击 “struts-2.3.x-all.zip” 下载

    5.环境的搭建(重点)

      1)加入 jar 包: 复制 strutsappsstruts2-blankWEB-INFlib 下的所有 jar 包到当前 web 应用的 lib 目录下

         参照G:...SSH 框架struts-2.3.15.3-allstruts-2.3.15.3appsstruts2-blankWEB-INFlib

            

      2)在 web.xml 文件中配置 struts2: 复制 strutsappsstruts2-blank1WEB-INFweb.xml 文件中的过滤器的配置到当前 web 应用的 web.xml 文件中

        web.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xmlns="http://java.sun.com/xml/ns/javaee"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     5     id="WebApp_ID" version="3.0">
     6     
     7     <!-- 配置 Struts2 的Filter -->
     8      <filter>
     9         <filter-name>struts2</filter-name>
    10         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    11     </filter>
    12 
    13     <filter-mapping>
    14         <filter-name>struts2</filter-name>
    15         <url-pattern>/*</url-pattern>
    16     </filter-mapping>
    17     
    18     
    19     
    20     </web-app>

        

      3)在当前 web 应用的 classpath 下添加 struts2 的配置文件 struts.xml: 复制 struts1appsstruts2-blankWEB-INFclasses 下的 struts.xml 文件到当前 web 应用的 src 目录下.

        1) 关联 DTD约束:G:...SSH 框架struts-2.3.15.3-allstruts-2.3.15.3srccoresrcmain esourcesstruts-2.3.dtd

          

      2) 复制struts2 : G:...SSH 框架struts-2.3.15.3-allstruts-2.3.15.3srccoresrcmain esourcesstruts2.xml

    1 <?xml version="1.0" encoding="UTF-8" ?>
    2 <!DOCTYPE struts PUBLIC
    3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    4     "http://struts.apache.org/dtds/struts-2.3.dtd">
    5 
    6 <struts>
    7 //编写struts2 相关配置文件
    8     
    9 </struts>

        

    接下来开始 Struts2  的学习之路

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    《EffectiveJava中文第二版》 高清PDF下载
    《MoreEffectiveC++中文版》 pdf 下载
    《啊哈c语言》 高清 PDF 下载
  • 原文地址:https://www.cnblogs.com/jasonHome/p/5726927.html
Copyright © 2011-2022 走看看