1

我有以下问题:当我在我的项目上运行 ant 命令时,它编译成功,但是当我尝试执行操作时,它给了我以下错误:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [registrate] associated with context path [/Core].

我怀疑在部署时,struts.xml文件没有被占用或其他东西。因为当我在 Eclipse 上运行我的应用程序时,它会完成它应该做的所有事情。请帮我。

我的struts.xml文件:

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

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



<struts>

  <package name="addMenu" namespace="/" extends="json-default">

      <action name="registrate" class="com.coreRestaurant.menu.MenuAction">
          <result type="json" >
          <param name="root">json</param>
          </result>
      </action>

      <action name="read" class="com.coreRestaurant.menu.MenuAction" method="readMenuById">
          <result type="json" >
          <param name="root">json</param>
          </result>
      </action>

      <action name="add" class="com.coreRestaurant.menu.MenuAction" method="addMenu">
         <result type="json" >
          <param name="root">json</param>
         </result>
      </action>

      <action name="update" class="com.coreRestaurant.menu.MenuAction" method="updateMenu">
         <result type="json" >
          <param name="root">json</param>
         </result>
      </action>

   </package>

   <package name="menuItems" namespace="/" extends="json-default">

      <action name="readMenuItemById" class="com.coreRestaurant.menuItem.MenuItemAction">
          <result type="json" >
          <param name="root">json</param>
          </result>
      </action>

   </package>

</struts>

还有我的 MenuAction 类:

package com.coreRestaurant.menu;

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

import com.coreRestaurant.menuItem.MenuItem;
import com.coreRestaurant.menuItem.MenuItemService;
import com.coreRestaurant.validator.InputValidator;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import org.json.*;

public class MenuAction extends ActionSupport implements ModelDriven<Menu>{
private final String INVALID_INPUT = "Error code : Invalid input";
private final String DATABASE_PROBLEMS = "Error code : Database problems";

private boolean areAllMenuItemDataFormatsCorrect = true;

private Menu menu = new Menu();

private MenuItem menuItem = new MenuItem();

private InputValidator validator = new InputValidator();

     private String json;

public String execute(){
    MenuService menuService = new MenuService();
    if(menuService.testDatabaseConnectionU()){
    setJson(new Gson().toJson(menuService.getMenuNames()));

    }else{
        setErrorToBeSentBackToClientSide(DATABASE_PROBLEMS);
    }
    return SUCCESS;
}

public String readMenuById(){
    MenuService menuService = new MenuService();
    if(menuService.testDatabaseConnectionU()){
    setJson(new Gson().toJson(menuService.getSpecificalMenuNameById(menu.getId())));

    }else{
        setErrorToBeSentBackToClientSide(DATABASE_PROBLEMS);
    }
    return SUCCESS;

}

public String addMenu(){

    menu.setMenu(new Gson().fromJson(json, Menu.class));
    MenuService menuService = new MenuService();
    if(menuService.testDatabaseConnectionU()){
    if(validator.isCorrectMenuOrFoodName(menu.getName())){
        menuService.addMenu(menu);
    }else{
        setErrorToBeSentBackToClientSide(INVALID_INPUT);
    }

    }else{
        setErrorToBeSentBackToClientSide(DATABASE_PROBLEMS);
    }
    return SUCCESS;
}

public String updateMenu(){

    MenuItem item;
    MenuService menuService = new MenuService();

    if(menuService.testDatabaseConnectionU()){

    menu.setMenu(new Gson().fromJson(json, Menu.class));

    if(validator.isCorrectMenuOrFoodName(menu.getName())){

        menuService.updateSpecificMenuNameById(menu.getId(), menu.getName());

        JSONObject obj = new JSONObject(json);

        JSONArray foodArray = obj.getJSONArray("foodName");

        JSONArray priceArray = obj.getJSONArray("price");

        List<MenuItem> updatedMenuItems = new ArrayList<MenuItem>();

        for (int i = 0; i < foodArray.length(); i++){

             item = new MenuItem();

             item.setMenuId(menu.getId());

             if(validator.isCorrectMenuOrFoodName(foodArray.get(i).toString()) &&
                    validator.isPriceFormatCorrect(priceArray.get(i).toString())){

                  item.setName(foodArray.get(i).toString());

                  item.setPrice(Double.parseDouble(priceArray.get(i).toString()));

                  updatedMenuItems.add(item);

             }else{

                  areAllMenuItemDataFormatsCorrect = false;
        }

    }

    if(areAllMenuItemDataFormatsCorrect==true){
        MenuItemService itemService = new MenuItemService();
        itemService.updateMenuItemsListByMenuId(updatedMenuItems, menu.getId());
    }else{
        setErrorToBeSentBackToClientSide(INVALID_INPUT);
    }

    }else{
        setErrorToBeSentBackToClientSide(INVALID_INPUT);
    }

    }else{
        setErrorToBeSentBackToClientSide(DATABASE_PROBLEMS);
    }
    return SUCCESS;
}


public String getJson() {
    return json;
}


public void setJson(String json) {
    this.json = json;
}


@Override
public Menu getModel() {
    return menu;
}

private void setErrorToBeSentBackToClientSide(String error){
    String errorCode = error;
    setJson(new Gson().toJson(errorCode));
}


}

还有我的蚂蚁build.xml文件:

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



<project name="Core" default="all" basedir=".">
<property name="application_name" value="Core"/>
<!-- Configure properties to access the Manager application -->
<property name="url"      value="http://localhost:8080/manager/text"/>
<property name="username" value="tomcat"/>
<property name="password" value="tomcat"/>
<taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/>
<property name="path"     value="/${application_name}"/>


<target name="init">
  <property environment="ENV"/>
  <property name="src_all.dir"       value="src"              />
  <property name="src_web_inf.dir"   value="web/WEB-INF"              />
  <property name="src.dir"        value="src"              />
  <property name="web-inf.dir"     value="WEB-INF"            />
  <property name="classes.dir"     value="WEB-INF/classes"            />
  <property name="jsp.dir"        value="."            />
  <property name="build.dir"      value="build"            />
  <property name="pkg-dist.name"  value="${name}-pkg" />
  <property name="tomcat.home" location="${ENV.TOMCAT_HOME}/Tomcat 7.0"/>
  <echo message="${tomcat.home}" />
  <property name="tomcat.server.lib" location="${tomcat.home}/lib"/>
  <echo message="${tomcat.server.lib}" />
  <property name="myapp.lib" location="web/WEB-INF/lib"/>
   <echo message="${myapp.lib}" />
   <path id="lib.classpath">
   <fileset dir="${tomcat.server.lib}" includes="*.jar"/>
   <fileset dir="${ENV.ANT_HOME}/lib" includes="*.jar"/>
   <fileset dir="${myapp.lib}" includes="*.jar"/>
  </path>
</target>


<target name="clean" depends="init">
  <delete dir="${classes.dir}" />
  <delete dir="${web-inf.dir}" />
</target>



<target name="prepare" depends="clean">
  <mkdir dir="${classes.dir}" />
 </target>



  <target name="compile" depends="prepare">
    <mkdir dir="${classes.dir}"/>
  <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.classpath"/>
  <copy todir="${classes.dir}">
      <fileset dir="${src.dir}" excludes="**/*.java"/>
  </copy>

</target>



<target name="war" depends="compile">
   <war destfile="${application_name}.war" webxml="${src_web_inf.dir}/web.xml">
  <fileset dir="web"/>
    <classes dir="${classes.dir}"/>
    <lib dir="${myapp.lib}">
    </lib>
   </war>
 </target>



<target name="deploy_war_local" depends="war">
 <copy todir="${tomcat.home}/webapps" overwrite="true">
     <fileset dir="." includes="*.war" />
  </copy>
 <delete dir="${classes.dir}" />
 <delete dir="${web-inf.dir}" />
 </target>



 <target name="deploy_remote_to_imbi" description="Install web application" depends="war">
    <deploy url="${url}" username="${username}" password="${password}"
            path="${path}" war="file:${application_name}.war"/>
     <delete dir="${classes.dir}" />
      <delete dir="${web-inf.dir}" />
  </target>

  <target name="undeploy_remote_from_imbi" description="Remove web application" depends="init">
    <undeploy url="${url}" username="${username}" password="${password}"
            path="${path}"/>
  </target>



<target name="redeploy_remote_to_imbi" depends="undeploy_remote_from_imbi, war">
    <deploy url="${url}" username="${username}" password="${password}"
            path="${path}" war="file:${application_name}.war"/>
      <delete dir="${classes.dir}" />
      <delete dir="${web-inf.dir}" />
</target>

<target name="all" depends="deploy_war_local"/>

</project>

因此,例如,当我localhost:8080/Core/read?id=2从 Eclipse 运行后运行时,它给了我 JSON,这没关系。但是当我制作 WAR 文件并在 tomcat 中运行并运行相同的命令时,我得到了错误。

但有一件事:当我启动 Tomcat 并运行它时,我得到以下信息:

Unable to locate configuration files of the name `struts-plugin.xml`

Unable to locate configuration files of the name `struts.xml`
4

0 回答 0