RRT*_*RTW 6 configuration jsp action namespaces struts2
我是Struts2的初学者,我知道这个问题在这里被问过很多次,但是我试图解决这个问题并在这里阅读了很多线程,花了6个小时仍无法正常工作。确实需要更多建议...
这是我的包裹
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
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
还有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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
服务器是Tomcat 8.0.38,启动时没有错误。但是当我访问
它给了我这个(作为标题)错误,如果我访问
我会得到常规的404结果。
现在我不知道,欢迎任何建议或提示...
相关问题:没有映射与上下文路径关联的命名空间和操作名称的操作
如果您使用 URL 来调用操作,请确保此 URL 已映射到 Struts 配置。要解决 URL 映射问题,您可以使用config-browser插件。只需将此插件添加到您的项目依赖项中,部署后,您就可以访问一个网站,该网站显示运行时配置以及用于调用该操作的可用 URL。例如,如果您在端口 8080 上本地运行 Tomcat 并将应用程序部署在context,那么您可以使用以下命令访问插件的 URL
http://localhost:8080/[context]/config-browser/index.action
Run Code Online (Sandbox Code Playgroud)
您可以单击侧边栏命名空间下的操作页面上的任何可用操作。另请注意,如果在包中找不到您的操作,则它可能在default包中。Struts 在default命名空间中对不在从 URL 映射的命名空间中的操作进行额外的搜索。
查看配置浏览器插件来调试配置问题。
要将 url 正确映射到操作,需要两个参数:操作名称和命名空间。
Struts 在启动时加载 xml 配置,并且它应该知道
struts.xml. 默认情况下,它会在类路径中查找具有已知名称(例如struts.xml. 然后它解析文档并创建运行时配置。此配置用于为操作 url 查找适当的配置元素。如果请求期间没有找到这样的元素,则返回 404 错误代码,并显示消息:There is no Action mapped for namespace and action name。此消息还包含用于查找操作配置的命名空间和操作名称。然后您可以在 中检查您的配置设置
struts.xml。有时,存储的操作名称和命名空间ActionMapping指向错误的操作。ActionMapper这些值由插件使用的可能有不同实现的值决定。还有另一个设置可能会影响此映射器和映射,但如果您收到此消息,则使用的 URL 未在运行时配置中映射任何操作配置,那么要点是相同的。如果您不知道应该使用哪个 URL,您可以尝试使用 config-browser插件来查看可用的 URL 列表。