首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

spring3引文 struts2 action访问不到

2013-12-07 
spring3注解 struts2 action访问不到ssh集成(struts2,spring3,hibernate4)使用spring3的注解,项目启动后点

spring3注解 struts2 action访问不到
ssh集成(struts2,spring3,hibernate4)
使用spring3的注解,项目启动后点击登录访问不到action
求懂得spring3注解技术的帮忙指点一下!谢谢了!

HTTP Status 404 - /oa/login.action

--------------------------------------------------------------------------------

type Status report

message /oa/login.action

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.47





配置如下:

web.xml
--------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
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_3_0.xsd">
<display-name>bonsoftoa</display-name>

<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>sessionTimeout</param-name>
<param-value>1800</param-value>
</context-param>
<listener>
<listener-class>com.oa.util.session.AppSessionListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/**/*.xml</param-value>
</context-param>
</web-app>



struts.xml
------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<package name="web"  extends="struts-default">        
<action name="login" class="loginAction">
<result name="success">/index.jsp</result>
</action>  
</package>
</struts>




spring的配置文件
----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns:p="http://www.springframework.org/schema/p"
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:context="http://www.springframework.org/schema/context"
    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.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">


    <context:annotation-config/>

    <context:component-scan base-package="com.oa.login.action"/>
      
  
   <bean
        id="environmentVariablesConfiguration"
        class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig"
        p:algorithm="PBEWITHMD5ANDDES"
        p:passwordEnvName="APP_ENCRYPTION_PASSWORD" />

    <bean
        id="configurationEncryptor"
        class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"
        p:config-ref="environmentVariablesConfiguration" />

    <bean
        id="propertyConfigurer"
        class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer" >



        <constructor-arg ref="configurationEncryptor" />

        <property name="locations" >

            <list>
                <value>
classpath:jdbc.properties
                </value>
            </list>
        </property>
    </bean>

    <context:property-placeholder location="classpath:jdbc.properties" />

    <bean
        id="commonsConfigurationFactoryBean"
        class="com.bonsoft.oa.util.CommonsConfigurationFactoryBean"
        p:encryptor-ref="configurationEncryptor"
        p:systemPropertiesModeName="SYSTEM_PROPERTIES_MODE_OVERRIDE" >

        <constructor-arg>
            <bean class="org.apache.commons.configuration.PropertiesConfiguration" >
                <constructor-arg value="jdbc.properties" />
            </bean>
        </constructor-arg>
    </bean>

    <bean
        id="propertiesConfiguration"
        factory-bean="&amp;commonsConfigurationFactoryBean"
        factory-method="getConfiguration" />

    <bean
        id="methodLoggerAdvisor"
        class="com.oa.util.LoggerAdvice" >
    </bean>

    <bean
        id="springUtil"
        class="com.oa.util.SpringUtil" >
    </bean>

    <aop:config>
        <aop:aspect
            id="originalBeanAspect"
            ref="methodLoggerAdvisor" >
            <aop:pointcut
                id="loggerPointCut"
                expression="execution(* com.oa.service.impl.*.*(..))" />
            <aop:around
                method="aroundAdvice"
                pointcut-ref="loggerPointCut" />
        </aop:aspect>
    </aop:config>
</beans>



action代码如下:
---------------------------------------------------------------------------------------------
package com.oa.login.action;

import .....

@Controller("loginAction")
public class LoginAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {
protected final Log logger = LogFactory.getLog(getClass());
private Map att;
private HttpServletRequest request = null;
private HttpServletResponse response;

@Resource
LoginService loginService;

public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}

public void setSession(Map att) {
this.att = att;
}
public String execute() throws Exception {

return SUCCESS;

}
}


登录页面如下:
--------------------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>   
    <title>login</title>
  </head>

  <body>
  <form action="${pageContext.request.contextPath}/login.action">
      <table border="1" cellspacing="0" cellpadding="0" align="center">


      <tr>
        <td  width="150" align="center">用户名:</td>
        <td  width="150" align="center"><input type="text" name="userName" id="userName"></td>
      </tr>
      <tr>
        <td  width="150" align="center">密码:</td>
        <td  width="150" align="center"><input type="password" name="loginPwd" id="loginPwd"></td>
      </tr>
      <tr >
      <td colspan="2" align="right"><input type="submit" value="登录"></td>    
      </tr>
    </table>
  </form> 
  </body>
</html>



调试了很久就是访问不到action
我自己怀疑一下几点造成的
1.web.xml未加载struts.xml造成的
2.spring3的注解不完整,或注解错误造成的
3.jsp页面的访问路径不正确造成的
4.web.xml/struts.xml/spring的配置文件配置错误造成的
恳请各位指点一下,谢谢了!
spring3注解 访问不到Action struts2注解访问不到action 注解配置问题
[解决办法]
struts-plugin.jar加了没有,如果没有,就说明struts的action不是交给了spring管理,所以访问不到spring容器中的对象。。。还有就是看看你的action加没加@component注解,还有名字有没有弄错。。。
[解决办法]
@Controller("loginAction")去掉试下
[解决办法]
我看你web.xml和spring配置文件里加入了些其他东西,搭建ssh环境框架要一点点来,逐步集成,这样才能便于发现问题所在,另外搭建环境要了解每一步配置的意义和含义,例如楼主配置的<context:component-scan>标签不对。我建议楼主,从头开始搭建框架。
[解决办法]
<action name="login" class="loginAction">里的class写完整,com.oa.login.action.LoginAction,不更名试试

热点排行