struts2内置form标签配合模型驱动配置action再IDEA中标签name属性标红

报错信息

There is no Action mapped for namespace [/] and action name [register] associated with context path [/struts2_03].

表单:

<%--
    @program: struts2_02
    @description
    @author: LIANG
    @create: 2021-01-22 11:19
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--导入struts标签库--%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
    <head>
        <title>login</title>
    </head>
    <body>
        <s:fielderror></s:fielderror>
        <s:form  action="register" namespace="/user">
            <s:textfield name="username" label="用户名"></s:textfield><br>
            <s:password name="password" label="密码"></s:password><br>
            <s:textfield name="birthday" label="生日"></s:textfield><br>
            <%-- 使用ognl表达式            --%>
            <s:checkboxlist list="#{'':'吃饭','':'喝水','':'睡觉'}" label="爱好" name="hobby"></s:checkboxlist>
            <s:radio list="#{'true':'已婚','false':'未婚'}" label="是否已婚" name="married"></s:radio>
            <s:submit value="注册" ></s:submit>
        </s:form>
    </body>
</html>

action:

package org.ccit.com.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.ccit.com.domain.User;
import org.ccit.com.service.IUserService;
import org.ccit.com.service.impl.UserServiceImpl;


/**
 * @program: struts2_02
 * @description
 * @author: LIANG
 * @create: 2021-01-22 11:22
 **/
public class UserAction extends ActionSupport implements ModelDriven<User> {

    //声明变量时new
    private User user=new User();
    @Override
    public User getModel() {
        return user;
    }
    /**
     * @Description: 注册功能实现
     * @param
     * @return: java.lang.String
     * @Author: LIANG
     * @Date: 2021/1/22 16:25
     */
    public String register(){
        //调用业务方法
        IUserService iUserService = new UserServiceImpl();
        System.out.println(user.toString());
        iUserService.register(user);
        return NONE;
    }
}

在这里插入图片描述
IDEA 提示:
在这里插入图片描述

有毒…
刚开始 无法运行 以为无法使用模型驱动封装
但是 过了会时间 可以运行了 虽然标红但是运行也不报错(估计刚开始是缓存问题)
但还是不知道为什么标红 添加action后 name属性就会标红

There is no Action mapped for namespace [/] and action name [register] associated with context path [/struts2_03].
猛然发现 报错更action写法有联系
action有两种写法
一种写/user/register.action (再action属性中连同命名空间写全)// 这种在2.5版本中好像不适用了
一种是action属性中只写action名 namesapce属性填写命名空间

报错是因为 我起初没有写namespace属性 acthon中也只写了register 后来缓存清楚后 代码跑起来了
但是还是不知道为啥报错

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值