【问题标题】:There is no action mapped etc.. In Struts 2没有动作映射等。在 Struts 2
【发布时间】:2012-07-14 19:23:17
【问题描述】:

我知道还有一个关于此的问题,但我只想说我看过其他所有内容或其他内容。所以,我目前正在构建我的 Struts 2 项目的结构。我使用 Struts 2.3.4、JBoss 7.1 和 Eclipse Indigo。我还将所有必要的 jar 包含到我的项目中。问题是当我运行我的应用程序(将项目添加到 Jboss,在服务器上运行)并转到“http://localhost:8080/booxstore/”时,我得到了这个:

Etat HTTP 404 - There is no Action mapped for namespace [/] and action name [] associated with context path [/booxstore]

我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">
  <display-name>Booxstore</display-name> 

  <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>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

</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>
    <constant name="struts.devMode" value="false" />
    <package name="pages" namespace="/pages" extends="struts-default">
        <action name="afficher" class="com.booxstore.controller.DisplayAction" >
            <result name="SUCCESS">/center.jsp</result>
        </action>
    </package>
 </struts>

我的行动:

/**
 * 
 */
package com.booxstore.controller;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class DisplayAction extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 8199854978749642334L;

    public String execute() throws Exception{
        System.out.println("IN");
        return Action.SUCCESS;
    }
}

我的 JSP 只有纯文本并导入了 struts 2 标签。基本上无论我做什么,我都无法获得资源。如果我转到“http://localhost:8080/booxstore/”或“http://localhost:8080/booxstore/DisplayAction”,我会得到“没有映射操作”,如果我尝试直接访问 jsp,我会得到 404。请注意,我的战争已在服务器上部署并启用。

【问题讨论】:

    标签: struts2 web.xml action-mapping


    【解决方案1】:

    index.jsp 放在WebContent 文件夹下,将pages 文件夹移动到WEB-INF,然后将struts.xml 更改为:

    <struts>
     <constant name="struts.devMode" value="false" />
     <package name="pages" extends="struts-default">
        <action name="afficher" class="com.booxstore.controller.DisplayAction" >
            <result name="SUCCESS">/WEB-INF/pages/center.jsp</result>
        </action>
     </package>
    </struts>
    

    我认为问题在于应用程序没有找到您放入配置文件的 jsps。如果您不想公开它们,META-INF 文件夹不是放置 jsps 页面的地方,WEB-INF 更适合此目的。

    【讨论】:

    • 现在证明这一点,没有namespace="/pages"
    • 索引正常,现在操作结果为“未定义”但成功。走错路了?
    • 您必须以http://localhost:8080/afficher.action 的身份访问该操作,因为这是该操作的名称。
    • afficher 或 afficher.action 给我同样的答案
    • 如果您将center.jsp 移动到WebContent 并将实际结果替换为center.jsp(而不是/WEB-INF...),您是否遇到同样的问题?
    【解决方案2】:

    为防止对映射的误解,请将配置浏览器插件 jar 添加到您的应用程序中。它将允许您浏览所有页面。警告!仅在开发或测试中部署依赖项,而不是在生产中。为此限制使用 Maven 配置文件。

    http://struts.apache.org/release/2.3.x/docs/config-browser-plugin.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 2019-10-16
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多