开发者

No result defined for and result success

开发者 https://www.devze.com 2023-03-18 10:07 出处:网络
I\'m new to struts 2 and I keep getting this error message \'No result defined for action com.jjpeople.action.HelloAction and result success\' while I think I have properly refrenced it.What might be

I'm new to struts 2 and I keep getting this error message 'No result defined for action com.jjpeople.action.HelloAction and result success' while I think I have properly refrenced it.What might be the problem?

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

&开发者_StackOverflow中文版lt;%@ 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>

Action class

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;
    }
}


In your xml file

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

result name is "success",But in your Action class you returnd "SICCESS" variable.So please check the SUCCESS variable value.


The result is struts.xml and Action didn't equals.So returned the exception you didn't be defined.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号