0

这是错误消息:

警告:未找到指定操作的配置:命名空间中的“欢迎”:“”。表单动作默认为“动作”属性的文字值。

我已经尝试将支柱放在下面,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>

目录结构

登录.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>

错误信息 错误

4

1 回答 1

1

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

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

于 2015-12-10T09:50:08.370 回答