1.web.xml
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
2.加入编码格式
<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>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.由于spring 3.0 里不在提供对jotm的封装,我们可以手动的编写加入代码如下
/*
* Copyright 20010-2011
*/
package com.demo.spring.jotm;
import javax.naming.NamingException;
import javax.transaction.SystemException;
import org.objectweb.jotm.Current;
import org.objectweb.jotm.Jotm;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
/**
* @author fenglingcorp
*/
@SuppressWarnings("rawtypes")
public class JotmFactoryBean implements FactoryBean, DisposableBean {
private Current jotmCurrent;
private Jotm jotm;
public JotmFactoryBean() throws NamingException {
// Check for already active JOTM instance.
this.jotmCurrent = Current.getCurrent();
// If none found, create new local JOTM instance.
if (this.jotmCurrent == null) {
// Only for use within the current Spring context:
// local, not bound to registry.
this.jotm = new Jotm(true, false);
this.jotmCurrent = Current.getCurrent();
}
}
public void setDefaultTimeout(int defaultTimeout) {
this.jotmCurrent.setDefaultTimeout(defaultTimeout);
// The following is a JOTM oddity: should be used for demarcation
// transaction only,
// but is required here in order to actually get rid of JOTM's default
// (60 seconds).
try {
this.jotmCurrent.setTransactionTimeout(defaultTimeout);
} catch (SystemException ex) {
// should never happen
}
}
public Jotm getJotm() {
return this.jotm;
}
public Object getObject() {
return this.jotmCurrent;
}
public Class getObjectType() {
return this.jotmCurrent.getClass();
}
public boolean isSingleton() {
return true;
}
public void destroy() {
if (this.jotm != null) {
this.jotm.stop();
}
}
}
4.加入jotm事务和xpool数据源
<!-- jotm -->
<bean id="jotm" class="com.demo.spring.jotm.JotmFactoryBean" />
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>
<!-- StandardXAPoolDataSourc 数据源 -->
<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
<property name="dataSource">
<bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="driverName">
<value>${datasource.driverClassName}</value>
</property>
<property name="url">
<value>${datasource.g_db_w_url}</value>
</property>
<property name="user">
<value>${datasource.g_db_w_username}</value>
</property>
<property name="password">
<value>${datasource.g_db_w_password}</value>
</property>
</bean>
</property>
<property name="user">
<value>${datasource.g_db_w_username}</value>
</property>
<property name="password">
<value>${datasource.g_db_w_password}</value>
</property>
<property name="maxSize">
<value>5</value>
</property>
<property name="minSize">
<value>2</value>
</property>
</bean>
5.加入aop支持
<aop:config>
<aop:pointcut id="serviceMethods"
expression="execution(* com.demo.spring.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" rollback-for="Exception" />
<tx:method name="insert*" rollback-for="Exception" />
<tx:method name="save*" rollback-for="Exception" />
<tx:method name="update*" rollback-for="Exception" />
<tx:method name="del*" rollback-for="Exception" />
<tx:method name="remove*" rollback-for="Exception" />
<tx:method name="*" read-only="true" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
编写登入的类
package com.demo.spring.actions;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.demo.spring.forms.LoginForm;
import com.demo.spring.service.LoginServiceInterface;
import com.demo.spring.util.Constants;
@SuppressWarnings("deprecation")
public class LoginAction extends SimpleFormController {
private LoginServiceInterface loginservice;
public LoginServiceInterface getLoginservice() {
return loginservice;
}
public void setLoginservice(LoginServiceInterface loginservice) {
this.loginservice = loginservice;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
LoginForm loginForm = (LoginForm) command;
if (isValid(loginForm)) {
request.getSession().setAttribute(Constants.USERNAME_KEY,
loginForm.getUsername());
request.getSession().getServletContext()
.getRequestDispatcher("/list.do?method=list")
.forward(request, response);
return null;
} else {
Map modle = errors.getModel();
modle.put("loginForm", loginForm);
return new ModelAndView(getFormView(), modle);
}
}
public boolean isValid(LoginForm loginForm) {
if (loginservice.isValid(loginForm.getUsername(),
loginForm.getPassword())) {
return true;
} else {
return false;
}
}
}
完整代码在附件中
分享到:
相关推荐
MyEclipse7.5+flex4+spring3.0.5+struts2.2.1+hibernate3.6.0+blazeds4.0.0.14931完美整合方案 内附所需jar包和源代码
Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解
Spring+MVC+3.0.5+Spring+3.0.5+MyBatis3.0.4全注解实例详解
Spring 3.0.5+MyBatis3.0.4整合例子,这个是我自己写的例子.
完整的描述了整个整合的过程,并且对其拆分讲解,没有非常繁琐的原理,都是针对项目讲解
Spring_MVC_3.0.5+Spring_3.0.5+MyBatis3.0.4全注解实例详解三.doc
基于Django3.0.5+Python3.7+SQLite的博客系统源码 基于Django3.0.5+Python3.7+SQLite的博客系统源码 基于Django3.0.5+Python3.7+SQLite的博客系统源码 基于Django3.0.5+Python3.7+SQLite的博客系统源码 基于...
CXF2.7+SPRING3.0.5+HIBERNATE3.6final+STRUTS2的所有jar包完全配好了,并已经成功项目中应用,使用者只需将文件解压拷到项目的lib文件夹下即可
Struts 1.3.10+Spring3.0.5+Mybatis3.1.1框架整合的所有jar包都有,挺详细的
NULL 博文链接:https://junjun16818.iteye.com/blog/1109094
搭建zkoss CE6.0+spring3.0.5+hibernate3.6+oracle10g+mysql5框架最全包,下载就收益,省的再去别的地方找。需要的就赶紧下载吧。。
Struts2 2.1.8 + Spring 3.0.5 + Hibernate 3.6.0 + JPA2的jar包整合到一起了 里面还有JSON的jar包,是SS2H+JPA的学习必备. 这里面都是jar包,如果想查看web.xml,struts.xml,application.xml,persistense.xml的写法,...
activiti5.14+spring4.0+srping Mvc4.0+mybatis3.0.5+maven环境搭建,可以跑起来,并且可以逆向生成相关的数据库表
NULL 博文链接:https://31841814.iteye.com/blog/1124111
jsf是j2ee规范,spring是目前流行的管理依赖,控制事务的框架,mybatis是流行的sql映射框架,三者集成起来应用,形成完善的web框架
使用myeclipse 8.5开发环境 是学习JSP + SSH开发的好例子 在学习《21天学通JAVA WEB开发视频》过程编写的DEMO
spring3.0.5 +hibernahe3.6.10 springMVC 基于注解 的注册登录例子 包含事物的简单配置
开发SpringMVC+Hibernate技术使用的lib集合,测试过的。