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

 

转载于:https://www.cnblogs.com/LoganChen/p/6942304.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值