关于Struts2中的No result defined for action and result input错误

今天学习struts2的转换器,省略表单填写页面,直接在网址栏里输入参数,然后转交到Action处理,然后在jsp页面中显示参数值。

配置好了struts.xml:
<!-- struts2的转换器,在Action中接收表单中各种各样类型的参数,然后再页面中输出-->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true"/>
<package name="conversion" namespace="/conversion" extends="struts-default">
<action name="user" class="jweb.web.action.UserAction14">
<result>
/convertion.jsp
</result>
</action>
</package>

写好Action:

public class UserAction14 extends ActionSupport {

    //接受字符串类型表单数据
    private String username;
    //接受整型类型表单数据
    private int age;
    //接受日期类型表单数据
    private Date birthday;
    //接受List类型表单数据
    private List<String> hobby;
    //接受Map类型表单数据
    private Map<String,String> users;

    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        return super.execute();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public List<String> getHobby() {
        return hobby;
    }

    public void setHobby(List<String> hobby) {
        this.hobby = hobby;
    }

    public Map<String, String> getUsers() {
        return users;
    }

    public void setUsers(Map<String, String> users) {
        this.users = users;
    }


}

写好convertion.jsp页面:

<body>

      struts2的转换器,在Action中接收表单中各种各样类型的参数,然后在本页面中输出:<br>
      <hr>
      http://localhost:8080/JavaWebStruts2/conversion/user?username=a&age=23<br>
             用户名: <s:property value="username"/><br>
             年龄: <s:property value="age"/><br>
      http://localhost:8080/JavaWebStruts2/conversion/user?birthday=1988-08-06<br>
             生日:<s:property value="birthday"/><br>
              <s:date name="birthday" format="yyyy/MM/dd HH:mm:ss"/><br>
      http://localhost:8080/JavaWebStruts2/conversion/user?hobby=aa&hobby=bb&hobby=cc<br>
             兴趣爱好:<s:property value="hobby"/><br>
      http://localhost:8080/JavaWebStruts2/conversion/user?users['a']=usera&users['b']=userb&users['c']=userc<br>
             用户Map:<s:property value="users"/>
</body>

开始做实验,先在地址栏输入http://localhost:8080/JavaWebStruts2/conversion/user?username=a&age=23,莫名其妙的出现错误:there is no action mapped on namespace [/] and action [user] associeted with [JavaWebStruts2]….当时就慌了,因为昨天晚上已经出现过这种情况,反复检查代码,配置文件,确认没错,试了几十遍,依旧报这个错误。往下看错误信息,发现最后一行:You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties file. 于是赶紧将之前在struts.xml中配置的<constant name="struts.devMode" value="true"/>改为:<constant name="struts.devMode" value="false"/>改完后运行发现问题初步解决。
接着实验日期类型数据的转换,在地址栏输入http://localhost:8080/JavaWebStruts2/conversion/user?birthday=1988-08-06,发现报错:
Messages: •No result defined for action jweb.web.action.UserAction14 and result input.
应该是表单参数和Action的参数类型、个数不一致导致的,看了半天,尝试着将UserAction14中的execute方法的返回值变成“INPUT”,然后将struts.xml中的result添加属性:name=”input”. 运行,没有报错。但是发现jsp视图中的<s:date name="birthday" format="yyyy/MM/dd HH:mm:ss"/> 并没有起作用,而且“生日:1988-08-06”。显然,代码没有任何错误,检查n遍,无果,只在jsp视图中好加入<s:debug></s:debug>。继续运行,打开debug,发现值栈Value Stack Contents中:
fieldErrors一栏“{birthday=[Invalid field value for field “birthday”.]} ”,
actionMessages一栏“ [Error setting expression ‘birthday’ with value [‘1988-08-06’, ]] ”
貌似是因为地址栏的birthday值得格式错误,可是是现在想不出格式“1988-08-06”错在哪,上网查阅,无意中发现,英文日期格式:08/06/1988,中文日期格式:1988-08-06,于是将地址栏日期改为http://localhost:8080/JavaWebStruts2/conversion/user?birthday=08/06/1988,发现问题终于解决!发现了什么不对,于是去查看浏览器的语言——-默认语言被改成了“英语(美国)en-US”!!!!!!原来是昨晚做国际化实验的时候将浏览器语言改了,却忘记了改回来。于是将默认语言改为中文,然后将上面所有的改动(false改回true,去掉name=”input”属性)全部撤销。然后运行,通过!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值