作者:李da寕 | 来源:互联网 | 2023-01-19 17:39
Noactionconfigfoundforthespecifiedurlurl路径下找不到action,原因是stuts-config.xml文件配置错误。demo的项目文件如下
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>StrutsSampledisplay-name>
<servlet>
<servlet-name>actionservlet-name>
<servlet-class>org.apache.struts.action.ActionServletservlet-class>
<init-param>
<param-name>configparam-name>
<param-value>/WEB-INF/struts-config.xmlparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>actionservlet-name>
<url-pattern>*.dourl-pattern>
servlet-mapping>
<welcome-file-list>
<welcome-file>index.htmlwelcome-file>
<welcome-file>index.htmwelcome-file>
<welcome-file>index.jspwelcome-file>
<welcome-file>default.htmlwelcome-file>
<welcome-file>default.htmwelcome-file>
<welcome-file>default.jspwelcome-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
org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.