document文档document.forms[0]文档中的第一个表单document.forms[0].title文档中的第一个表单的title表单
document.forms[0].title.value文档中的第一个表单的title表单的内容
HttpServletRequest request = ServletActionContext.getRequest();
String ids = request.getParameter("ids");
为了在Action处理过程中可以访问到当前请求HttpServerRequest对象,通俗的说就是request.getParameter可以取到值.
我们可以使用依赖注入机制的接口注入方法.接口注入需要的是已经被实现了的接口。这个接口包含了相应属性的setter,为Action提供值
我做的这个神话网的例子中,有一个action需要request.getParameter取得value,所以我实现了ServletRequestAware接口,同进声明了一个
HttpSerletRequest的属性.看起来好像是线程不安全的,其实在struts2中并没有问题,因为每个请求过来的时候都会产生一个新的Action对象实例,
它并没有和其他请求共享一个对象,所以不需要考虑线程安全问题。
<?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"
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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.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">
<context:annotation-config />
<context:component-scan base-package="com.demo.cyd" />
<!-- 使用C3P0方式连接数据库-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout" value="10000" />
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
<property name="acquireIncrement" value="3" />
<property name="maxIdleTimeExcessConnections" value="1800" />
</bean>
<!-- 整合Hibernate操作数据库 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.demo.cyd.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<!-- 创建Hibernate操作数据库的模版 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用XML方式配置事物-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="update*" />
<tx:method name="delete*" />
<tx:method name="add*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="bussinessService" expression="execution(public * com.demo.cyd.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" />
</aop:config>
<!-- 配置事物所使用的数据库连接方式 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
分享到:
相关推荐
最近在做个项目,用的是webwork+spring+hibernate,在网上看了不少webwork+spring的配制方式,大多都是老的配制方式,比如2.1.7的,webwork2.2.4新加了很多功能,和spring的配制也简单了很多,我做了一个简单的登录...
本文将详细介绍Spring事务配置中的五种方法,并结合示例来探讨每种方法的特点。 #### 二、Spring事务配置的基本组成部分 Spring事务配置通常由以下三个主要部分组成: 1. **DataSource**:这是数据源配置,用于...
在IT行业中,SSH框架是指Struts2、Hibernate和Spring三个开源框架的组合,它们共同构建了一个强大的企业级应用开发平台。SSH框架的配置文件是理解并有效使用这三个框架的关键,下面我们将逐一解析这些配置文件的主要...
本资源包“常用的WEB项目配制文件model”包含了Struts、Hibernate、Java和Spring框架的一些关键配置文件,这些都是构建高效、可扩展的Web应用不可或缺的部分。接下来,我们将深入探讨这些框架以及它们的配置文件。 ...
Spring和Hibernate也广泛使用注解来简化配置过程,提高代码的可读性和可维护性。 - **Spring框架**:Spring使用注解来定义Bean的作用域、生命周期等属性,同时还支持依赖注入等高级特性。 - **Hibernate框架**:...
3. **数据持久化**:利用 JPA 或 Hibernate,你可以轻松地在 JBoss 中实现数据库的数据持久化操作。 4. **JMS 集成**:JBoss 内置了 JMS 服务,可以实现消息队列和发布/订阅模型,实现异步处理和解耦。 5. **...
总之,JdbcTemplate在SpringBoot中提供了一种轻量级的数据库访问方式,虽然功能不如ORM框架如Hibernate或MyBatis强大,但其简洁性和灵活性使得它在一些简单场景下成为不错的选择。学习JdbcTemplate可以帮助我们理解...