首页 > 其他 > 详细

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

时间:2015-11-27 06:37:53      阅读:251      评论:0      收藏:0      [点我收藏+]

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

我是根据马士兵老师的Struts2教程学习的,学习笔记都是按照马士兵老师视频顺序。我做笔记的目的就是对每一个知识点都记录下来,方便以后复习查找知识什么的,如果有人也在看马士兵老师的视频可以一起交流。最后还得感谢马士兵老师的视频,特别喜欢他的讲课风格

马士兵老师视频下载,所有的java视频都有。

一、学习工具下载

  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路径带了空格

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

原文:http://www.cnblogs.com/xulimessage/p/4999499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!