jfy3d(剑事)BLOG

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  37 随笔 :: 0 文章 :: 363 评论 :: 0 Trackbacks

学习的时候看了网上的一些配置教程,没有达到想要的结果
查了好多资料才弄出来,随后后自己整理出一个配置方法

web.xml 
// 这里不需要配置字符过滤,网上有的例子加了,实际上
webwork.properties里设置如下就可以了页面也是GBK
webwork.locale=zh_CN
webwork.i18n.encoding=GBK
---------------------------
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <listener>
  <listener-class>com.atlassian.xwork.ext.ResolverSetupServletContextListener</listener-class>
 </listener>
    <!--
    <servlet>
    <servlet-name>context</servlet-name>
             <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
             <load-on-startup>1</load-on-startup>
     </servlet>
     -->
    <servlet>
        <servlet-name>webwork</servlet-name>
        <servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
        <load-on-startup>3</load-on-startup>
    </servlet>

 <servlet>
  <servlet-name>freemarker</servlet-name>
  <servlet-class>com.opensymphony.webwork.views.freemarker.FreemarkerServlet</servlet-class>
  <load-on-startup>10</load-on-startup>
 </servlet>

    <servlet-mapping>
        <servlet-name>webwork</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

 <servlet-mapping>
  <servlet-name>freemarker</servlet-name>
  <url-pattern>*.ftl</url-pattern>
 </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <taglib>
        <taglib-uri>webwork</taglib-uri>
        <taglib-location>/WEB-INF/webwork.tld</taglib-location>
    </taglib>

</web-app>

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

xwork.xml

==================---------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd">

<xwork>

  <include file="webwork-default.xml"/>
    <package name="users" extends="webwork-default"
        externalReferenceResolver="com.atlassian.xwork.ext.SpringServletContextReferenceResolver">

        <interceptors>
            <interceptor name="reference-resolver" class="com.opensymphony.xwork.interceptor.ExternalReferencesInterceptor"/>
            <interceptor-stack name="myDefaultWebStack">
                <interceptor-ref name="defaultStack"/>
                <interceptor-ref name="reference-resolver"/>
                <interceptor-ref name="model-driven"/>
       <interceptor-ref name="params"/>
            </interceptor-stack>
        </interceptors>

<default-interceptor-ref name="myDefaultWebStack"/>
        <action name="blogUser" class="com.jsblog.action.BlogUserAction">
   <external-ref name="baseDao">baseDaoTarget</external-ref>     //这里是把applicationContext里配置的DAO 注入action里 action里要有baseDao属性
   <result name="success">/add.htm</result>
  </action>
-------------------------------------------------------------------------

applicationContext.xml

---------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="no" default-dependency-check="none" default-lazy-init="false">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName">
            <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
        </property>
        <property name="url">
            <value>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jsblog;SelectMethod=cursor</value>
        </property>
        <property name="username">
            <value>sa</value>
        </property>
        <property name="password">
            <value>jfy</value>
        </property>
    </bean>

    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource"/>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/jsblog/BlogUserForm.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    net.sf.hibernate.dialect.SQLServerDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>


    <bean id="baseDaoTarget" class="com.jsblog.dao.BlogUserDao">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>


</beans>
---------------------------------------------------------------------------

BlogUserDao.java
---------------------------------------------------------------------------
package com.jsblog.dao;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import org.springframework.orm.hibernate.HibernateCallback;
import org.springframework.orm.hibernate.SessionFactoryUtils;
import com.jsblog.BlogUserForm;

import java.io.Serializable;
import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;

public class BlogUserDao extends HibernateDaoSupport implements BaseDao {

    public void insert(BlogUserForm bloguser) {
        getHibernateTemplate().save(bloguser);
    }

 

 

}

posted on 2005-11-06 23:48 剑事 阅读(7536) 评论(4)  编辑  收藏 所属分类: webworkhibernatespring

评论

# re: Spring + hibernate + webwork + freemarker 整合配置 2007-05-22 10:26 剑客
不错,收藏了。

楼主有struts2.0的对应配置么?  回复  更多评论
  

# re: Spring + hibernate + webwork + freemarker 整合配置 2007-06-29 15:01
能不能发webwork2-spring.jar给我呀,我都找了好常时间了,我的邮箱是cg_zhangkai@163.com,谢谢!!!!  回复  更多评论
  

# re: Spring + hibernate + webwork + freemarker 整合配置 2007-08-20 10:30 simple
怎么没有关于这些配置一点说明了?
有的看不大懂!  回复  更多评论
  

# re: Spring + hibernate + webwork + freemarker 整合配置 2007-09-18 12:41 Ankdy
freemarker要不要配置才可以用的?  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: