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(转发到结果)

  • 相关阅读:
    python第十一天
    python第七天(字符编码,字符与字节,文件操作)
    python第六天(元组、字典、集合)
    python第五天
    python第四天
    根据数据库文件,查找对应的数据库
    Windows 路径问题
    32位及64位操作系统的程序问题
    好玩的获取目录信息的例子[C#]
    C# 反射相关的东西
  • 原文地址:https://www.cnblogs.com/LoganChen/p/6942304.html
Copyright © 2011-2022 走看看