欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

No result defined for action com.jmq.java.action.BookAction and result success 解决struts2问题

程序员文章站 2022-05-24 09:30:53
...

@TNo result defined for action com.jmq.java.action.BookAction and result success 解决struts2问题OC

No result defined for action com.jmq.java.action.BookAction and result success 解决struts2问题

**关于struts2中出现这样的404问题 首先检查有没有配置过滤器和tomcat有无错误 struts.xml中<result
要配对
其次是execute()或其他方法中的返回值必须是String类型!

No result defined for action com.jmq.java.action.BookAction and result success 解决struts2问题

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="book" extends="struts-default">
        <action name="book1" class="com.jmq.java.action.BookAction"  >
            <result name="SUCCESS" >/login.jsp</result>
        </action>
    </package>

</struts>

action.class

public class BookAction extends ActionSupport {
    @Override
    public String execute() throws Exception {
        System.out.println("成功进入struts2");
        System.out.println("hello struts2!!!!");
        return SUCCESS;
    }
    public String login(){
        System.out.println("成功进入struts2");
        System.out.println("hello struts2!!!!");
        return "book";
    }
}

这里只要将SUCCESS改成"success"就可以了
相关标签: struts2 java