谁能帮助我解决 struts2 和休眠以解决特定异常:HTTP 404 - 没有为命名空间映射的操作

who's can help me with struts2 and hibernate to solve a particular exception: HTTP 404 - There is no Action mapped for namespace

我正在学习如何使用 struts2 和休眠,但我无法解决此异常 "There is no Action mapped for namespace [/] and action name [registrar_barrios] associated with context path [/ConsultarPatente]."。我知道这个问题被问过很多次了,但在某些情况下很常见,我们开始吧:

下一个是建立在eclipse上的。

1.- 项目浏览器 https://www.dropbox.com/s/4gg52h64e4hz64s/package.png?dl=0

2.- 代码(src 和 WebContent folers)。 https://www.dropbox.com/s/x3q9qtq050a8anv/Files.rar?dl=0

3.- 我认为 AgregarBarrioAction 和 registrar_barrios 不起作用。

4.- 数据库。

CREATE TABLE `barrio_table` (
  `barrioId` int(11) NOT NULL auto_increment,
  `Nombre` varchar(24) collate utf8_bin NOT NULL,
  PRIMARY KEY  (`barrioId`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4 ;

5.- AgregarBarrioAction 代码。

package com.java.rmo.actions;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.java.rmo.dao.BarrioDAO;
import com.java.rmo.dao.BarrioDAOImpl;
import com.java.rmo.model.Barrio;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


@Namespace(value="/")
public class AgregarBarrioAction extends ActionSupport
implements ModelDriven<Barrio>
{
    private static final long serialVersionUID = -6659925652584240539L;


    private Barrio barrio = new Barrio();
    private List<Barrio> barrioList = new ArrayList<Barrio>();
    private BarrioDAO barrioDAO = new BarrioDAOImpl();


    @Override
    public Barrio getModel()
    {
        return barrio;
    }

    @Action
    (
        value="agregarBarrio",
        results={@Result(location="/registrar_barrios.jsp", type="redirect")}   
    )
    public String add()
    {
        barrioDAO.saveBarrio(barrio);
        return SUCCESS;
    }

    @Action
    (
        value="consultarBarrio",
        results={@Result(location="/registrar_barrios.jsp")}
    )
    public String list()
    {
        setBarrioList(barrioDAO.listBarrio());
        return SUCCESS;
    }

    public Barrio getBarrio() 
    {
        return barrio;
    }

    public void setBarrio(Barrio barrio)
    {
        this.barrio = barrio;
    }

    public List<Barrio> getBarrioList() 
    {
        return barrioList;
    }

    public void setBarrioList(List<Barrio> barrioList) 
    {
        this.barrioList = barrioList;
    }


}

6.- registrar_barrios.jsp 代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@taglib uri="/struts-tags" prefix="s"%>
<!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>Insert title here</title>
</head>
<body>
<s:form action="agregarBarrio">
    <s:textfield name="nombre" label="Nombre" />
    <s:submit />
</s:form>

<s:if test="consultarBarrio.size() > 0">
    <div class="content">
    <table class="barrioTable" cellpadding="5px">
        <tr class="even">
            <th>Nombre</th>
        </tr>
        <s:iterator value="consultarBarrio" status="barrio">
            <tr
                class="<s:if test="#barrio.odd == true ">odd</s:if><s:else>even</s:else>">
                <td><s:property value="nombre" /></td>
            </tr>
        </s:iterator>
    </table>
    </div>
</s:if>
</body>
</html>

帮帮我,我很感激你。祝你好运!!!

错误

There is no Action mapped for namespace [/] and action name [registrar_barrios] associated with context path [/ConsultarPatente].

告诉您您的操作不可访问。这并不奇怪,因为您没有 @Action(name="registrar_barrios")

你的行动是 agregarBarrioconsultarBarrio:

@Action(value="agregarBarrio", 
    results={@Result(location="/registrar_barrios.jsp", type="redirect")}   
)


@Action(value="consultarBarrio",
    results={@Result(location="/registrar_barrios.jsp")}
)

第一个结果也是不按顺序使用 redirect。删除它。