-
Spring管理Struts2 注解方式!无法找到请求Aaction 20
1. web.xml配置 内容
<!-- 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring/applicationContext.xml</param-value>
</context-param>
<!-- Spring Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- log4j Listener -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Proxool Listener -->
<listener>
<listener-class>org.bbs.framework.core.db.ProxoolListener</listener-class>
</listener>
<!-- Spring提供的一个用来防止内存泄露的监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- Open Session In View Filter -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Character Encoding Filter -->
<filter>
<filter-name>Set Character Encoding</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>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 延长action中属性的生命周期, -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Struts2 Filter -->
<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,resources/struts/struts.xml</param-value>
</init-param>
<init-param>
<param-name>actionPackages</param-name>
<param-value>org.bbs.framework.modules.sysmgr.controllers</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>2. 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.devMode" value="false" />
<!-- 将对象交给spring管理 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 指定资源编码类型 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 指定每次请求到达,重新加载资源文件 -->
<constant name="struts.i18n.reload" value="false" />
<!-- 指定每次配置文件更改后,自动重新加载 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 国际化资源文件 -->
<constant name="struts.custom.i18n.resources" value="resources/content/Language" />
<!-- 默认后缀名 -->
<constant name="struts.action.extension" value="do,action,jhtml,," />
<!-- Struts Annotation -->
<constant name="actionPackages" value="org.bbs.framework.modules.sysmgr.controllers"/>
</struts>3. 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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"><!-- 使用 annotation -->
<context:annotation-config />
<!-- 使用 annotation 自动注册bean,并检查@Controller, @Service, @Repository注解已被注入 -->
<context:component-scan base-package="*" />
<!-- hibernate属性配置 -->
<context:property-placeholder location="classpath:resources/hibernate/hibernate.properties"/><!-- C3P0 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${hibernate.connection.driver_class}"/>
<property name="jdbcUrl" value="${hibernate.connection.url}"/>
<property name="properties">
<props>
<prop key="user">${hibernate.connection.username}</prop>
<prop key="password">${hibernate.connection.password}</prop>
</props>
</property>
</bean>
<!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- value 所在实体类所在包 必写 -->
<property name="packagesToScan" value="org.bbs.framework.modules.domain,org.bbs.framework.modules.sysmgr.domain"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
</props>
</property>
<property name="lobHandler" ref="lobHandler" /><!-- Spring下处理blob字段的配置 -->
</bean>
<!-- Spring下处理blob字段的配置 -->
<bean id="lobHandler" lazy-init="true" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
</bean>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="true" />
<!-- 配置事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置注解实现管理事务(cglib:proxy-target-class="true") -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /></beans>4. 继承ActionSupport 请求处理类
package org.bbs.framework.modules.sysmgr.controllers;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.bbs.framework.core.action.BaseAction;
import org.bbs.framework.modules.sysmgr.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;import com.opensymphony.xwork2.ActionSupport;
@Controller
public class SystemLoginAction extends ActionSupport{private static final long serialVersionUID = 8509806371231995998L;
@Autowired
private UserServiceImpl userServiceImpl;
public SystemLoginAction (){
System.out.println("初始化SystemLoginAction!");
}
/**
* 用户登陆
*
* @return
*/
@Action(value = "/login", results = {
@Result(name = "SUCCESS", location = "index.jsp"),
@Result(name = "ERROR", location = "index.jsp") })
public String login() {
System.out.println("登陆成功");
return "SUCCESS";
}
}我发布成功后,在浏览器上请求 http://127.0.0.1:8080/bbs/login 报404错误!· 请求地址不存在!··什么原因·???
问题补充:<div class="quote_title">qiankun 写道</div><div class="quote_div">login方法执行了没有,把location 设置成/index.jsp试试</div> <br /> <br />访问ingdex.jsp 是可以访问到的··2012年3月02日 12:37
相关推荐
字母组合如“Pplan2Ddo3Ccheck4Aaction4:3.1.3”可能是在描述某种编程语言的结构化流程,例如使用字母P、D、C、A来表示计划、执行、检查和行动。另外,“CASEDFDDDA:B.C.283456SCPFDN-SPADHIPO(+//)173.3.1”等看似...
##### 2. **C语言语法分析器实现** - **LR解析器**:LR解析器是一种自下而上的解析技术,可以高效地处理复杂的语法结构。 - **扫描器(词法分析器)**:首先需要实现一个扫描器来识别输入中的词法单元(例如关键字...
- **Robot Framework RIDE 1.3**:RIDE(Robot Framework IDE)是一款用于 Robot Framework 的集成开发环境,可以帮助用户更高效地编写和管理测试用例。 - **下载地址**:...
文档采用中英文对照的方式,为中文用户提供方便,尤其是对英文技术文档理解有困难的用户。 文档分为多个章节,每个章节介绍bash的一个方面: - NAME:介绍bash的名称和用途。 - SYNOPSIS:提供了bash的用法概览,如...
幻灯片1TOGAF企业架构主讲人翁杰点击添加文本点击添加文本点击添加文本点击添加文本PDCA戴明环在面销和电销过程中的运用PPlan计划DDo实施AAction总结CCheck检查PLAN计划阶段分析
在Vue.js应用中,Vuex是一个强大的状态管理库,它帮助组织和管理应用程序的状态。当应用变得复杂时,单个Store文件可能会变得庞大且难以维护。此时,Vuex的模块化拆分就显得尤为重要,它允许我们将Store拆分为多个...