org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.

时间:2021-11-02 10:37:11

No action config found for the specified url

  url路径下找不到action,原因是stuts-config.xml文件配置错误。

  demo的项目文件如下:

org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.

  使用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