No action config found for the specified url
url路徑下找不到action,原因是stuts-config.xml文件配置錯誤。
demo的項目文件如下:

使用jsp文件夾中的login.jsp文件調用action:
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>用戶登錄</title> </head> <body> <!-- 標准登錄框 --> <div id="Login_LoginForm"> <div>賬號登錄</div> <form method="post" action="loginng.do"> 賬號:<input name="username" type="text"> 密碼:<input name="password" type="password"> <a target="_blank" href="register.jsp">免費注冊</a> <input type="submit" value="登錄"> <input type="reset" value="重新輸入"> </form> </div> </body> </html>
web.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>StrutsSample</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
struts-config.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="loginForm" type="org.sunnywen.struts.LoginActionForm"> </form-bean> </form-beans> <action-mappings> <action path="/loginng" name="loginForm" type="org.sunnywen.struts.LoginAction"> <forward name="loginSuccess" path="/index.jsp"></forward> </action> </action-mappings> </struts-config>
LoginActionForm是繼承ActionForm的類,LoginAction是繼承Action的類,此時運行將會出現錯誤:org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.
原因是JSP文件是在jsp文件夾中,action="loginng.do"會自動去尋找同一文件夾下(即jsp文件夾)的loginng.do,而在struts-config.xml中配置的action的path是配置在根目錄下,所以應當如下進行配置:
<action-mappings> <action path="/jsp/loginng" name="loginForm" type="org.sunnywen.struts.LoginAction"> <forward name="loginSuccess" path="/index.jsp"></forward> </action> </action-mappings>
轉載請注明轉載地址:http://www.cnblogs.com/FlyingPuPu/p/5129631.html
