在看struts2,但是怎么改都是报404,以下是代码,求高手指点,jsp的代码就没发了,在线等高手指点
我一访问http://localhost:8080/yuandongstruts2action/index就报以下的错误HTTPStatus404-ThereisnoAc...
我一访问http://localhost:8080/yuandongstruts2action/index就报以下的错误
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [index] associated with context path [/yuandongstruts2action].
以下是我自己写的代码
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.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>
struts2的代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="indexaction" extends="struts-default" namespace="/">
<action name="index" class="com.yuandong.action.IndexAction1">
<result>/ActionIntroduction.jsp</result>
</action>
</package>
</struts>
action
public class IndexAction1 {
public String execute(){
return "success";
}
}
分不多,就是个意思。。。再次谢谢!! 展开
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [index] associated with context path [/yuandongstruts2action].
以下是我自己写的代码
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.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>
struts2的代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="indexaction" extends="struts-default" namespace="/">
<action name="index" class="com.yuandong.action.IndexAction1">
<result>/ActionIntroduction.jsp</result>
</action>
</package>
</struts>
action
public class IndexAction1 {
public String execute(){
return "success";
}
}
分不多,就是个意思。。。再次谢谢!! 展开
1个回答
展开全部
根据错误提示,应该把namespace去掉,因为当前的namespace配置相当于从工程的根目录开始,即错误中提示的/yuandongstruts2action,这种是以绝对路径的方式来寻找你的Action,这样的话,你自己对比一下路径就清楚了:/yuandongstruts2action/com.yuandong.action.IndexAction1/找不到的,因为这不是绝对路径,而去掉了namespace,则默认相对路径,即项目中的Class文件所在的目录,这样就不会出错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询