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

  • 相关阅读:
    opencv3.2.0形态学滤波之腐蚀
    Ubuntu下卸载QT5.7.1再重装
    opencv3.2.0形态学滤波之膨胀
    Direct3D中的绘制
    绘制流水线
    初始化Direct3D
    VS2012添加对DirectX SDK中需要文件的引用
    ASCII,Unicode 和通用方式
    对话框访问的7种方式【孙鑫老师教程】
    函数指针
  • 原文地址:https://www.cnblogs.com/LoganChen/p/6942304.html
Copyright © 2020-2023  润新知