zoukankan      html  css  js  c++  java
  • Struts2学习第三课 Struts2详解

    接着上次的课程

    这次我们看struts.xml

    修改如下:这里是加上命名空间,默认的是不加,我们手动加上时就要在访问时加上命名空间。

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
    
    <struts>
        <!-- package:包,struts2使用package来组织模块
            name属性:必须,用于其他包引用当前包
            extends: 当前包继承哪个包,继承的,即可以继承其中的所有的配置,通常情况下继承struts-default
            struts-default这个包在struts-default.xml文件中定义的-->
        <package name="helloWorld" extends="struts-default" namespace="/logan">
            <!-- 配置action:一个struts2的请求就是一个action
                name:对应一个Struts2的请求的名字,不包含扩展名 -->
            <action name="product-input">
                <result>/WEB-INF/pages/input.jsp</result>
            </action>
            
            <action name="product-save" class="logan.struts.study.Product" method="save">
                <result name="details">/WEB-INF/pages/details.jsp</result>
            </action>
            
        </package>
        
    </struts>

    我们再去访问地址http://localhost:8080/Struts2-2/product-input.action

    可以看到访问失败

    HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-input] associated with context path [/Struts2-2].
    
    type Status report
    
    message There is no Action mapped for namespace [/] and action name [product-input] associated with context path [/Struts2-2].
    
    description The requested resource is not available.
    
    Apache Tomcat/9.0.0.M15

    我们访问这个地址才能访问:http://localhost:8080/Struts2-2/logan/product-input.action

    action里面class的默认值是com.opensymphony.xwork2.ActionSupport

    默认的执行方法时execute

    result:结果,表示action方法执行后可能返回的一个结果。所以一个action节点可能会有多个result子节点。多个result子节点使用name来区分。

    name:标识一个result,和cation方法的返回值对应,的默认值是success。

    type:表示结果的类型,默认值为dispatcher(转发到结果)

  • 相关阅读:
    Windows 7 任务计划程序
    '7z' 不是内部或外部命令,也不是可运行的程序
    [转]国外人气最旺的软件测试网站
    AutoIT查找文件内容并修改保存
    BUG 太少
    excel表格数据导入sqlserver数据库
    RoR常见问题
    [转]漫画:程序员的一生
    [转]RubyInstaller: Getting Started with Rails and SQLite3
    [转]C#多线程学习(一) 多线程的相关概念
  • 原文地址:https://www.cnblogs.com/LoganChen/p/6942304.html
Copyright © 2011-2022 走看看