我是Struts2的初學者,我知道這個問題在這裏被問了很多次,但我試過要解決這個問題,並在這裏閱讀很多線索,花費6個小時,仍然無法完成工作。真的需要更多的建議...Struts2沒有Action映射的命名空間[/]和動作名稱[登錄]與上下文路徑[/ Struts2Test]相關聯
這裏是我的包
Struts2Test
+Struts2Test/src
+tw.com.rrstudio.java.test
-TestAction.java
+Struts2Test/build
+Struts2Test/WebContent
+Struts2Test/WebContent/META-INF
+Struts2Test/WebContent/WEB-INF/classes
+Struts2Test/WebContent/WEB-INF/lib
-Struts2Test/WebContent/WEB-INF/spring-context.xml
-Struts2Test/WebContent/WEB-INF/spring-mvc.xml
-Struts2Test/WebContent/WEB-INF/struts.xml
-Struts2Test/WebContent/WEB-INF/struts2-action.xml
-Struts2Test/WebContent/WEB-INF/web.xml
-Struts2Test/WebContent/error.jsp
-Struts2Test/WebContent/index.jsp
-Struts2Test/WebContent/TestAction.jsp
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context.xml
/WEB-INF/spring-mvc.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>tw.com.rrstudio.java.test</param-value>
</init-param>
</filter>
<jsp-config>
<taglib>
<taglib-uri>HTTP://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/tld/c.tld</taglib-location>
</taglib>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
而且也struts.xml的
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- struts 2.3.16.3 has problem of security,needing to set DynamicMethodInvocation=false -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.action.extension" value="do"/>
<constant name="struts.action.excludePattern" value="/jsp/.*?,/image/.*?,/css/.*?,/js/.*?,.*\\.jsp"/>
<package name="default" extends="json-default" ></package>
<package name="Strut2Test" extends="json-default" >
<global-results>
<result name="SystemErrorPage">/WebContent/error.jsp</result>
</global-results>
<action name="login" class="tw.com.rrstudio.java.test.TestAction">
<result name="index">/WebContent/index.jsp</result>
<result name="success">/WebContent/TestAction.jsp</result>
</action>
</package>
</struts>
的index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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=UTF-8">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=login.action">
<title>Index of Struts2Test</title>
</head>
<body>
<h1>Index of Struts2Test</h1>
<form action="testAction" method="post">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</form>
</body>
</html>
服務器是Tomcat 8.0.38,它以無錯誤啓動。但是,當我訪問
它給了我這個(標題)的錯誤,如果我訪問
我會得到一個正常的404結果。
現在我不知道,有什麼建議或提示,歡迎...
你爲什麼用Spring MVC的混合Struts2的?嘗試從web.xml中刪除任何Spring MVC引用,也從struts2過濾器中刪除actionPackages參數,並註釋Spring objectFactory設置。另外請注意,你需要struts2-spring-plugin使用spring作爲objectFactory,而SpringMVC與它無關。 –
因爲這是我的公司做到的,所以它是一個多年來存在的結構。我需要嘗試一些關於錯誤修復/新功能的東西,全部基於這種結構。 – RRTW
那麼,你最好的辦法就是看看你的配置和基於這個結構的工作項目配置(同一部分)之間的差異。特別注意到xml struts文件(我看到你有兩個,你只發布了一個)。但在這個單調乏味的工作之前,你仍然可以嘗試(如果不存在的話,可以添加它)[** config-browser-plugin **](https://struts.apache.org/docs/config-browser-plugin.html )並尋找'http://127.0.0.1:8080/Struts2Test/config-browser/actionNames.action':它會告訴你到底是什麼被映射到你的整個webapp中。值得一試; –