没有为结果定义和结果成功

时间:2011-07-07 11:10:42

标签: jsp struts2

我是struts 2的新手,我不断收到此错误信息'没有结果为动作定义com.jjpeople.action.HelloAction和结果成功',而我认为我已经正确地引用了它。可能是什么问题?< / p>

struts.xml中

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

    <constant name="struts.devMode" value="false" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <package name="tutiworks" extends="struts-default">  
        <action name="index">
            <result>/index.jsp</result>
        </action>       
        <action name="hello" class="com.jjpeople.action.HelloAction" method="execute">
                <result name="success">/welcome.jsp</result>
        </action>   
    </package>
</struts>

的index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Basic Struts 2 Application - Welcome</title>
</head>
    <body>
        <h1>Welcome To Struts 2!</h1>
        <p><a href="<s:url action='hello'/>">Hello World</a></p>
    </body>
</html>

动作类

package com.jjpeople.action;

import com.jjpeople.model.Hello;
import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport 
{
    private static final long serialVersionUID = 1L;
    private Hello hello;

    public String execute() throws Exception 
    {
        hello = new Hello();
        return SUCCESS;
    }
    public Hello getMessage() 
    {
        return hello;
    }
    public void setMessage(Hello hello) 
    {
        this.hello = hello;
    }
}

2 个答案:

答案 0 :(得分:0)

在您的xml文件中

<action name="hello" class="com.jjpeople.action.HelloAction" method="execute">                 <result name="success">/welcome.jsp</result>         </action>    

结果名称是“成功”,但在你的Action类中你返回“SICCESS”变量。所以请检查SUCCESS变量值。

答案 1 :(得分:0)

结果是struts.xml和Action没有等于。所以返回了你没有定义的异常。