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

  • 相关阅读:
    动态规划(DP),模拟
    递推,动态规划(DP),字符串处理,最佳加法表达式
    递归,动态规划,找最短路径,Help Jimmy
    动规,模拟,递推,最长公共子序列
    递归,递推,记忆化搜索,空间优化(数字三角形)
    递归,记忆化搜索,(棋盘分割)
    递归,搜索,回溯,最优路径(线段)
    web前端开发初学者必看的学习路线(附思维导图)
    一位资深程序员大牛给予Java初学者的学习路线建议
    假如时光倒流,我会这么学习Java
  • 原文地址:https://www.cnblogs.com/LoganChen/p/6942304.html
Copyright © 2011-2022 走看看