请各位高手帮忙解决..There is no Action mapped for namespace /hello,万分感谢!
本人小菜鸟一枚..在学习ssh2时..访问时老是报这个错误:HTTP Status 404 - There is no Action mapped for namespace /hello and action name demodoDemoQuery.
--------------------------------------------------------------------------------
type Status report
message There is no Action mapped for namespace /hello and action name demodoDemoQuery.
description The requested resource (There is no Action mapped for namespace /hello and action name demodoDemoQuery.) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.16
------------------------------------------------------------------------------------
在网上找了很多资料..但是按照他们说的做也没解决..所以在这里请教下各位高手...非常感谢!!!!
1.struts.xml是在src目录下
2.部署到tomcat下路劲为\WEB-INF\classes\struts.xml
3.访问路劲:http://localhost:8080/Demo/hello/demodoDemoQuery.action
struts.xml信息如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default" namespace="/hello">
<action name="demo*" class="demoAction" method="{1}">
<result name="doDemoQuery">/jsp/demoList.jsp</result>
</action>
</package>
</struts>
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>
<init-param>
<param-name>config</param-name>
<param-value>
struts-default.xml,struts-plugin.xml,struts*.xml
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- 配置CharacterEncoding,设置字符集 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring 配置和监听start -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/application*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- end -->
</web-app>
action代码:
package com.demo.action;命名空间 struts2 --------------------编程问答-------------------- 访问路径应该是http://localhost:8080/Demo/hello/demo/doDemoQuery.action
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.demo.pojo.Demo;
import com.demo.services.DemoServices;
import com.opensymphony.xwork2.ActionSupport;
import com.weichai.wserviceline.base.util.Pager;
@Controller
public class DemoAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
@Autowired
private DemoServices demoServices;
private Pager pager = new Pager();
private List<Demo> demoList;
public String doDemoQuery() {
demoList = demoServices.queryDemos(pager);
return "doDemoQuery";
}
/**
* method for get and set
* */
public Pager getPager() {
return pager;
}
public void setPager(Pager pager) {
this.pager = pager;
}
public List<Demo> getDemoList() {
return demoList;
}
public void setDemoList(List<Demo> demoList) {
this.demoList = demoList;
}
}
你中间少了一个/ --------------------编程问答-------------------- 不好意思,我看错了,上面回复错误,MD,csdn自己回复的帖子都不能修改。 --------------------编程问答-------------------- 在struts.xml的struts标签中加上一行<include file="struts-default.xml"/> --------------------编程问答-------------------- @rumlee
访问路径应该是http://localhost:8080/Demo/hello/demo/doDemoQuery.action
你中间少了一个/
-------------------------------
正确路劲就是我上面说的..demo*是表示我访问action的时候前面需要加demo --------------------编程问答-------------------- @rumlee
在struts.xml的struts标签中加上一行<include file="struts-default.xml"/>
---------------------------------------------------------------------
加上也没用的! --------------------编程问答-------------------- <action name="demo*" class="demoAction" method="{1}">改成<action name="demo*" class="com.demo.action.DemoAction" method="{1}">呢? --------------------编程问答-------------------- 把你的Sping的配置文件ApplicationContext.xml发出来看看,看看你有没有用Spring来管理你的demoAction --------------------编程问答-------------------- form里的action=? 是/hello/demodoDemoQuery.action吗? --------------------编程问答-------------------- <action name="demo*" class="com.demo.action.DemoAction" method="{1}">
访问:http://localhost:8080/Demo/demo/demo_doDemoQuery.action --------------------编程问答-------------------- @xsd219222
<action name="demo*" class="demoAction" method="{1}">改成<action name="demo*" class="com.demo.action.DemoAction" method="{1}">呢?
--------------------------------------------------------------------------------
这样改了也没用的. --------------------编程问答-------------------- spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>--------------------编程问答-------------------- @fangmingshijie
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- 启用spring注解支持 -->
<context:annotation-config />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@192.168.1.183:1521/WSLDEV">
</property>
<property name="username" value="wsladmin"></property>
<property name="password" value="password"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
</bean>
<!--
定义事务处理类,不同的数据访问方式,事务处理类不同
比如:Hibernate操作的HibernateTransactionManager,JDBC操作的使用DataSourceTransactionManager
-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 定义事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义方法的过滤规则 -->
<tx:attributes>
<!-- 所有方法都使用事务 -->
<tx:method name="*" propagation="REQUIRED" />
<!-- 定义所有get开头的方法都是只读的 -->
<tx:method name="get*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 定义AOP配置 -->
<aop:config>
<!-- 定义一个切入点 -->
<aop:pointcut expression="execution (* com.demo.dao.*.*(..))"
id="services" />
<!-- 对切入点和事务的通知,进行适配 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="services" />
</aop:config>
</beans>
form里的action=? 是/hello/demodoDemoQuery.action吗?
--------------------------------------------------------------------
对的.
--------------------编程问答-------------------- 菜鸟也可以改错啊。
你的<package name="demo" extends="struts-default" namespace="/hello">
<action name="demo*" class="demoAction" method="{1}">
<result name="doDemoQuery">/jsp/demoList.jsp</result>
</action>
</package>
访问的时候acion=/hello/demodoDemoQuery.action
还有你的类名,应该为com.demo.action.DemoAction吧 --------------------编程问答--------------------
<!-- 将对象交给spring管理 -->
<constant name="struts.objectFactory" value="spring" />
这个有吗? --------------------编程问答-------------------- 你应该加上扫描action包的配置
<init-param>--------------------编程问答-------------------- 你spring 里面就没有定义demoAction 这个bean吧 --------------------编程问答-------------------- 如果你的项目框架中需要spring来管理你的action的话,需要在spring配置文件中加载一下,就像下面一样:
<param-name>struts.convention.action.packages</param-name>
<param-value>cn.damai.mplus.activity.channel.action</param-value>
</init-param>
<bean id="uploadAction" class="com.ec.action.UploadAction">
<property name="uploadService" ref="uploadService"></property>
</bean> --------------------编程问答-------------------- 解决没,后台进没。
补充:Java , Java SE