警告:无法找到操作或结果 - Struts2

时间:2014-02-08 03:05:47

标签: java jsp struts2

我目前正在开发一个struts2 + hibernate +基于spring的应用程序,我遇到了以下问题,在我点击'regist.jsp'页面中的提交按钮后,RegistAction.java收到请求,并返回'成功'的状态,但我不确定它是否已进入这种状态。

struts.xml文件有什么问题吗?

** * * 登录控制台 **

?? 08, 2014 10:53:18 ?? com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: Could not find action or result
No result defined for action org.leegang.action.RegistAction and result success
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
...

?? 08, 2014 10:53:18 ?? com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Exception occurred during processing request: No result defined for action org.leegang.action.RegistAction and result success
No result defined for action org.leegang.action.RegistAction and result success
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
    .apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:744)

* struts.xml * *

<?xml version="1.0" encoding="GBK"?>
<!-- 指定Struts2配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Struts2配置文件的根元素 -->
<struts>
    <!-- 配置了系列常量 -->
    <constant name="struts.custom.i18n.resources" value="messageResource"/>
    <constant name="struts.i18n.encoding" value="GBK"/> 

    <package name="lee" extends="struts-default">
        <!-- 定义处理用户请求的Action,指定该Action的实现类-->
        <action name="regist" class="org.leegang.action.RegistAction" >
            <result name="error">/error.jsp</result>
            <result name="success">/welcome.jsp</result>
        </action>

        <action name="home">
            <result>/regist.jsp</result>
        </action>

    </package>
</struts>

regist.jsp *

<%@ page language="java" contentType="text/html; charset=GBK"%>

<html>
<head>
<title>用户注册</title>
</head>
<body>
<form action="regist.action" method="post">
    <table align="center">
    <caption><h3>用户注册</h3></caption>
        <tr>
            <td>用户名:<input type="text" name="username"/></td>
        </tr>
        <tr>
            <td>年&nbsp;&nbsp;龄:<input type="text" name="age"/></td>
        </tr>
        <tr align="center">
            <td colspan="2"><input type="submit" value="注册"/><input type="reset" value="重填" /></td>
        </tr>
    </table>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

"/"命名空间添加到package元素:

<package name="lee" extends="struts-default" namespace="/">
...
</package>