Struts2_学习笔记(一)--------学习工具下载、HelloWorld、运行机制

Struts2_学习笔记(一)——–学习工具下载、HelloWorld、运行机制

一、学习工具下载

  1. 下载struts2 http://struts.apache.org/download.cgi#struts217(选择下载full distribution)
  2. 下载myeclipse,http://www.myeclipseide.com
  3. 下载tomcat,http://tomcat.apache.org
  4. 下载xwork,http://www.opensymphony.com/xwork(要注意的是下载与struts2的对应版本)
  5. 我使用的是struts2.3.3版本,xwork就包含在struts中。下面的配置信息是根据struts2.3.3版本写的

二、Struts2之 HelloWorld

  1. 新建一个Web project,project name 为 Struts2_0100_Introduction
  2. 将下载的Struts解压,再将apps文件夹下面的struts2-blank.war解压。
  3. 将解压出来的WEB-INFàclasses下的struts.xml复制到Struts_0100_introduction下的src目录下。
  4. 将解压出来的WEB-INFàclasses下的所有jar文件复制到Struts2_0100_Introduction下WEB-INFàlib下,刷新project可以Referenced Libraries下看到刚才的类库
  5. 将解压出来的WEB-INF下web.xml中的标签中的内容复制到新建项目中的web.xml中
  6. 修改struts.xml:注释struts标签中的内容(注释的好处是可以在配置的时候参考原来的配置)。将中的内容复制到注释外,将action的name改为hello,删除下的内容,添加“/Hello.jsp”,新建一个名为Hello.jsp的文件。
    struts.xml中的内容为:
<?xml version="1.0" encoding="UTF-8" ?>
        <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            "http://struts.apache.org/dtds/struts-2.0.dtd">

        <struts>         
             <constant name="struts.devMode" value="true" />
             <package name="default" namespace="/" extends="struts-default">

                <action name="hell">
                    <result>
                        /Hello.jsp
                    </result>
                </action>
            </package>
        </struts>
  1. 将项目部署到tomcat服务器上,在浏览中输入“http://localhost:8080/Struts2_0100_Introduction/hello” 就可以看到Hello.jsp 中的内容

三、 Struts2运行机制

  1. 客户端发出请求“http://localhost:8080/Struts2_0100_Introduction/hello”,URL地址请求发送到tomcat,tomcat找到Struts2_0100_Introduction/hello,并将请求交给相应的web application。
  2. web.xml中的过滤“/*”即所有地址,并将请求交给org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter。
  3. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter会在struts.xml查找相应的namespace,在相应的package中查找相应的action,并将其中的result返回到客户端

其他:

  1. 使用开发模式,及时对更改进行反馈
    在struts.xml中添加 设置value的值为true
  2. struts.xml不自动提示
    • window – preferences – 搜索 catalog – add
    • 选择key type为URI
    • key: http://struts.apache.org/dtds/struts-2.3.dtd
    • location: 对应的dtd文件,位于struts-core包中,解压开,指定相 应位置,如:F:\zk\struts-2.3.3\src\core\src\main\resources/struts-2.3.dtd
    • 如果还是不可以,将struts.xml以Myeclipse XML Editor打开
  3. devMode设为true就会出问题空指针问题
  4. tomcat路径带了空格
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xulimessage

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值