HTTP4.4錯(cuò)誤 There is no Action mapped for namespace [/] and action name [hello] associated with context path [/StrutsDemo].
.opensymphony.xwork2.config.ConfigurationException: There is no Action mapped for namespace [/] and action name [hello] associated with context path [/StrutsDemo].
?? ?at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:192) ~[struts2-core-2.5.5.jar:2.5.5]
?? ?at org.apache.struts2.factory.StrutsActionProxy.prepare(StrutsActionProxy.java:63) ~[struts2-core-2.5.5.jar:2.5.5]
?? ?at org.apache.struts2.factory.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37) ~[struts2-core-2.5.5.jar:2.5.5]
?? ?at com.opensymphony.xwork2.Default
以上是錯(cuò)誤信息,我用的是strtus2.5.5版本的,jar包都導(dǎo)入了,項(xiàng)目啟動(dòng)是沒(méi)有問(wèn)題的,只是在跳轉(zhuǎn)到相應(yīng)的Action時(shí)報(bào)錯(cuò),我已經(jīng)把目錄結(jié)構(gòu)以及類的目錄都寫好了,名稱也都核對(duì)過(guò)了,還是有問(wèn)題,麻煩大家?guī)兔匆幌拢?/strong>
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>StrutsDemo</display-name>
?
? <filter>
? ?? ?<filter-name>struts2</filter-name>
? ?? ?<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
? </filter>
?
? <filter-mapping>
? ?? ?<filter-name>struts2</filter-name>
? ?? ?<url-pattern>/*</url-pattern>
? </filter-mapping>
?? ?
? <welcome-file-list>
??? <welcome-file>default.jsp</welcome-file>
? </welcome-file-list>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
?? ?"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
?? ?"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
?? ?<package name="default" namespace="/" extends="struts-default">
?? ??? ?<action name="hello" class="com.imooc.action.HelloAction">
?? ??? ??? ?<result name="success">/result.jsp</result> <!-- 默認(rèn)name="success" -->????
?? ??? ?</action>
?? ?</package>
</struts>
default.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
??? pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>default.jsp</title>
</head>
<body>
?? ?<h1>This is default.jsp!</h1>
?? ?<center>${tip}</center>
?? ?<form action="hello.action" method="post">
?? ??? ?用戶名:<input type="text" name="username" />
?? ??? ?密碼:<input type="text" name="password"/>
?? ??? ?<input type="submit" value="登錄"/>
?? ?</form>
</body>
</html>
HelloAction.class
package com.imooc.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport {
?? ?@Override
?? ?public String execute() throws Exception {
?? ??? ?System.out.println("Hello Action execute!");
?? ??? ?return SUCCESS;
?? ?}?? ?
}
我已經(jīng)根據(jù)下面的提示查錯(cuò)了,但是還是出錯(cuò)。
1.struts.xml文件錯(cuò)誤。
? ? 這種錯(cuò)誤又分為以下幾種:
? ? 1)struts.xml文件名錯(cuò)誤。一定要注意拼寫問(wèn)題;
? ? 2)struts.xml文件放置路徑錯(cuò)誤。一定要將此文件放置在src目錄下。編譯成功后,要確認(rèn)是否編譯到classes目錄中;
? ? 3)struts.xml文件內(nèi)容錯(cuò)誤:啟動(dòng)頁(yè)面一定要是自己工程里有的jsp文件。
? ? ?<welcome-file-list>?
? ? ?<welcome-file>index.jsp</welcome-file>?
? ? ?</welcome-file-list>
? ? 如果你在Eclipse工程的WebContent文件夾下沒(méi)有這個(gè)index.jsp文件,也會(huì)報(bào)同樣的錯(cuò)誤。
? ? 比如我自己定義了一個(gè)login.jsp文件,放在WebContent文件夾下,就寫成
? ? <welcome-file>login.jsp</welcome-file>?
? ? 把login.jsp文件放在WEB-INF下自定義的jsp文件夾下,就寫成
? ? <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>
2.表單提交頁(yè)面的錯(cuò)誤
2017-02-11
filter里面看看