zoukankan      html  css  js  c++  java
  • 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路径带了空格
  • 相关阅读:
    ASP.NET中FileUpload中的代码怎么编写?
    JQuery EasyUI 根据数据动态生成datagrid,统计常用
    JQuery EasyUI window 用法
    jQuery EasyUI DataGrid 分页 FOR ASP.NET
    SQL server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表 的解决办法
    javascript 判断浏览器客户端
    Access, SQL Server, and Oracle数据类型的对应关系
    asp.net中的模态对话框
    [转]C++获取Windows时间的方法总结
    [转]Oracle开发与使用文章收藏
  • 原文地址:https://www.cnblogs.com/xulimessage/p/4999499.html
Copyright © 2011-2022 走看看