spring集成struts2访问不到action,也不报错

xiadong01asd 2012-03-22 11:42:40
action类:
我在LoginAction中的login()中输出了一句话,好像访问的时候根本就没这个action嘛,没任何输出,是不是少配置了啥啊?




package com.xcd.action;

import com.opensymphony.xwork2.ActionSupport;
import com.xcd.service.LoginService;

public class LoginAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 1L;

private LoginService loginService;

public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}

public String execute(){

return SUCCESS;
}

public String login(){
System.out.println("action...");
return SUCCESS;
}
}



配置文件:



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">

<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>

<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 指定spring配置文件的位置,这里是在类路径里 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<welcome-file-list>
<welcome-file>index.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.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<!-- <include file="example.xml"/> -->


<!--
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
-->
<!-- Add packages here -->

<package name="loginAction" namespace="/" extends="struts-default">
<default-action-ref name="login"></default-action-ref>
<action name="login" class="loginAction" method="login">
<result name="success">index.jsp</result>
</action>
</package>
</struts>


applicationContext.xml:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"></property>
</bean>

<bean id="userDAO" class="com.xcd.dao.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="loginService" class="com.xcd.service.LoginServiceImpl">
<property name="userDAO" ref="userDAO"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="loginAction" class="com.xcd.action.LoginAction" scope="prototype">
<property name="loginService" ref="loginService"></property>
</bean>

</beans>





...全文
409 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joyce-Luo 2014-04-17
  • 打赏
  • 举报
回复
引用 13 楼 cuiwei1026522829 的回复:
解决了么,我的也这个错误
根据昨天的配置,你的请求Url应该是"namespace/action-method",如namespace是test,action是AdminAction,方法是login(),URL就是"test/Admin-login"
另一花生 2014-04-17
  • 打赏
  • 举报
回复
解决了么,我的也这个错误
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ylovep 的回复:]

Java code
<package name="loginAction" namespace="/" extends="struts-default">
<default-action-ref name="login"></default-action-ref>
<action name="login" class="loginAction" method="……
[/Quote]

package标签上没method属性吧 那是action标签的属性
ylovep 2012-03-22
  • 打赏
  • 举报
回复
<package name="loginAction" namespace="/" extends="struts-default">
<default-action-ref name="login"></default-action-ref>
<action name="login" class="loginAction" method="login">
<result name="success">index.jsp</result>
</action>
</package>


在extends="struts-default"后面加上 method属性定义你要执行的方法
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
控制台输出信息好像也没报错啊:
2012-3-22 11:30:49 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.20.
2012-3-22 11:30:49 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2012-3-22 11:30:51 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-3-22 11:30:51 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2012-3-22 11:30:51 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1633 ms
2012-3-22 11:30:51 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-3-22 11:30:51 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.29
2012-3-22 11:30:51 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor host-manager.xml
2012-3-22 11:30:51 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2012-3-22 11:30:51 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ajax
2012-3-22 11:30:51 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory bulletin
2012-3-22 11:30:52 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2012-3-22 11:30:52 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2012-3-22 11:30:52 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2012-3-22 11:30:52 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2012-3-22 11:30:52 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory extjs
2012-3-22 11:30:52 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory extjs1
2012-3-22 11:30:53 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2012-3-22 11:30:53 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory spring_struts2
2012-3-22 11:30:54 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2012-3-22 11:30:54 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization started
2012-3-22 11:30:54 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing Root WebApplicationContext: startup date [Thu Mar 22 11:30:54 CST 2012]; root of context hierarchy
2012-3-22 11:30:54 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
2012-3-22 11:30:55 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@9468ca: defining beans [sessionFactory,userDAO,loginService,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,loginAction]; root of factory hierarchy
2012-3-22 11:30:57 org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
信息: Building new Hibernate SessionFactory
2012-3-22 11:31:00 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization completed in 6428 ms
2012-3-22 11:31:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2012-3-22 11:31:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-3-22 11:31:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts.xml, skipping
2012-3-22 11:31:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2012-3-22 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Initializing Struts-Spring integration...
2012-3-22 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Setting autowire strategy to name
2012-3-22 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: ... initialized Struts-Spring integration successfully
2012-3-22 11:31:03 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory struts2
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts.xml]
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Overriding property struts.i18n.reload - old value: false new value: true
2012-3-22 11:31:04 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Overriding property struts.configuration.xml.reload - old value: false new value: true
2012-3-22 11:31:05 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-3-22 11:31:05 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2012-3-22 11:31:05 org.apache.catalina.startup.Catalina start
信息: Server startup in 14671 ms
allan0527 2012-03-22
  • 打赏
  • 举报
回复
什么日志都没有。。。

显然HTTP请求没发到服务器端。。。
检查请求地址。
检查IE缓存。
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 dryzeng 的回复:]

http://localhost:8080/spring3_struts2_hibernate3/login.action呢?
页面有没什么信息?空白页?
[/Quote]

好了 犯了个低级错误 struts配置文件位置放错了
dryZeng 2012-03-22
  • 打赏
  • 举报
回复
http://localhost:8080/spring3_struts2_hibernate3/login.action呢?
页面有没什么信息?空白页?
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 dryzeng 的回复:]

把execute方法删了,如果还不行,把jsp的form贴上来看看。
[/Quote]

删了还是不行 我直接输入url访问的
项目名是:spring3_struts2_hibernate3

http://localhost:8080/spring3_struts2_hibernate3/login
dryZeng 2012-03-22
  • 打赏
  • 举报
回复
把execute方法删了,如果还不行,把jsp的form贴上来看看。
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 layuan110 的回复:]

Spring初始化和你调用的是不是同一个类?

将LoginService 声明为static试一下 。
[/Quote]

LoginService 我只是在action里面声明了一个这属性,是要让spring注入的 而且我现在没调用LoginService里的方法 现在一访问action就找不到匹配的action了

Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
echola_2020 2012-03-22
  • 打赏
  • 举报
回复
Spring初始化和你调用的是不是同一个类?

将LoginService 声明为static试一下 。
xiadong01asd 2012-03-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 crlystaldong 的回复:]

插件加了没?strut2-spring-pluin,
[/Quote]

插件加了 之前是404错误是因为项目是我直接复制之前创建的一个项目,改了名字没改myeclipse中的web context_root,我改过了,现在是找不到action了
小V小V志 2012-03-22
  • 打赏
  • 举报
回复
插件加了没?strut2-spring-pluin,

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧