2015-12-10 83 views
0

这是错误消息:没有映射为命名空间操作[/]和动作名称错误

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

我试图把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

的login.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> 

的welcome.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

+0

标题中的错误消息和问题中的错误消息是不同的。那么你会得到哪一个? “DTD Struts Configuration 3.0”还没有这样的东西。显示你的jsp。 –

+0

是的,它应该是'DTD Struts Configuration 2.5'。另外我发布了我的jsp – Andy

+0

你没有使用S2'2.5'。不要对'2.5'使用dtd。这只是一个警告。有什么不工作? –

回答

1

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

应该某处src下放置,并你喜欢的构建工具(Eclipse的蚂蚁,Maven的,ECC)被复制到WEB-INF/classes在编译时

+0

所以我把我的** struts.xml **放在'src'下,但是它没有把'struts.xml **应用到'WEB-INF/classes',我仍然得到相同的错误。 – Andy

+0

您的构建工具必须将struts.xml从其原始位置('src/whatever',例如'src/main/resources')复制到'WEB-INF/classes'。如果没有,那么在回到这个之前,你应该修复另一个问题。当它将复制'WEB-INF/classes'中的struts.xml时,它应该可以工作。 –

相关问题