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 为 Struts20100Introduction
  2.  将下载的Struts解压,再将apps文件夹下面的struts2-blank.war解压。
  3.  将解压出来的WEB-INFàclasses下的struts.xml复制到Struts0100introduction下的src目录下。
  4.  将解压出来的WEB-INFàclasses下的所有jar文件复制到Struts20100Introduction下WEB-INFàlib下,刷新project可以Referenced Libraries下看到刚才的类库
  5.  将解压出来的WEB-INF下web.xml中的<filter>标签中的内容复制到新建项目中的web.xml中
  6.  修改struts.xml:注释struts标签中的内容(注释的好处是可以在配置的时候参考原来的配置)。将<package>中的内容复制到注释外,将action的name改为hello,删除<result>下的内容,添加“/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/Struts20100Introduction/hello” 就可以看到Hello.jsp 中的内容

三、 Struts2运行机制

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

其他:

  1. 使用开发模式,及时对更改进行反馈

    在struts.xml中添加<constant name="struts.devMode" value="true" /> 设置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:zkstruts-2.3.3srccoresrcmainresources/struts-2.3.dtd
  • 如果还是不可以,将struts.xml以Myeclipse XML Editor打开
  1. devMode设为true就会出问题空指针问题
  2. tomcat路径带了空格

转载于:https://www.cnblogs.com/xulimessage/p/4999499.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值