关于这一点的另一个问题我知道,但是我只想说我看了一切或关于它。所以,我目前正在构建我的Struts 2项目的结构。我使用Struts 2.3.4,JBoss 7.1和Eclipse Indigo。我还将所有必要的jar包含在我的项目中。问题是当我运行我的应用程序(将项目添加到Jboss,Run On Server)并转到“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.请注意我的战争已部署并启用在服务器上。
答案 0 :(得分: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。如果您不希望将jsps页面公开,那么META-INF
文件夹不是放置jsps页面的地方,WEB-INF
更适合此目的。
答案 1 :(得分:0)
为防止对映射的误解,请将config浏览器插件jar添加到您的应用程序中。它将允许您浏览所有页面。警告!只在dev或测试中部署依赖项,从不生产。使用maven配置文件进行此限制。
http://struts.apache.org/release/2.3.x/docs/config-browser-plugin.html