gpt4 book ai didi

java - 没有为命名空间 [/] 映射操作且操作名称错误

转载 作者:行者123 更新时间:2023-12-01 10:45:40 25 4
gpt4 key购买 nike

这是错误消息:

WARNING: No configuration found for the specified action: 'welcome' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

我已经尝试将struts放在WEB-INF/classes下,但它仍然不起作用。我已经被困在这里几天了,请帮忙。

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 3.0//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login">
<result>login.jsp</result>
</action>
<action name="welcome" class="com.struts3.LoginAction" method="execute">
<result name="SUCCESS">welcome.jsp</result>
</action>
</package>
</struts>

directory structure

登录.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<h3>Welcome to Struts 2</h3>
<s:form action="welcome">
<s:textfield name="username" label="User Name"></s:textfield>
<s:textfield name="password" label="Password" type="password"></s:textfield>
<s:submit value="Login"></s:submit>
</s:form>
</body>
</html>

欢迎.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome To Struts</title>
</head>
<body>
<h3>Welcome <s:property value="username"/></h3>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Basic Struts2</display-name>
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

error message error

最佳答案

struts.xml 配置文件必须位于类路径的根目录上,然后位于 WEB-INF/classes 上,而不是位于子包中。

它应该放在src下的某个地方,并在构建时复制到WEB-INF/classes由您最喜欢的构建 -工具(Eclipse、Ant、Maven、ecc)。

关于java - 没有为命名空间 [/] 映射操作且操作名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34192649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com