- 浏览: 275301 次
-
文章分类
最新评论
-
yonghuuser:
< namespace > http://www. ...
使用 xfire 开发 web service 应用 -
悬空90:
牛人 呵呵
JCS 资料 -
悬空90:
谢谢分享 呵呵
JCS 应用 -
kuiye:
用于在客户端页面调用.
DWR util.js 整理(DWR 处理各种form表单Select/option,table等,List,Bean -
bo_hai:
好像不是原创呢!
抽象类与接口的区别
最近闲着用dwr做了个类似 163 新闻导航,在多种新闻类型下切换,无须刷新:
step1: 下载DWR包
step2: 构建数据库
step1: 下载DWR包
step2: 构建数据库
sql 代码
- if exists (select 1
- from sysobjects
- where id = object_id('AJAX_NEW')
- and type = 'U')
- drop table AJAX_NEW
- go
- /*==============================================================*/
- /* Table: AJAX_NEW */
- /*==============================================================*/
- create table AJAX_NEW (
- ID integer not null,
- NEW_TITLE VARCHAR(100) null,
- NEW_AUTHER VARCHAR(30) null,
- NEW_TYPE VARCHAR(30) null,
- NEW_CONTENT VARCHAR(500) null,
- constraint PK_AJAX_NEW primary key (ID)
- )
- go
step3 搭建Struts,Hibernate框架,生成Hibernae配置文件以及po类:
java 代码
- package com.fzfx88.conf;
- /**
- * AbstractAjaxNew generated by MyEclipse - Hibernate Tools
- * po 抽象类
- * auther huguoqing
- */
- public abstract class AbstractAjaxNew implements java.io.Serializable {
- // Fields
- private Integer id;
- private String newTitle;
- private String newAuther;
- private String newType;
- private String newContent;
- // Constructors
- /** default constructor */
- public AbstractAjaxNew() {
- }
- /** full constructor */
- public AbstractAjaxNew(String newTitle, String newAuther, String newType, String newContent) {
- this.newTitle = newTitle;
- this.newAuther = newAuther;
- this.newType = newType;
- this.newContent = newContent;
- }
- // Property accessors
- public Integer getId() {
- return this.id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getNewTitle() {
- return this.newTitle;
- }
- public void setNewTitle(String newTitle) {
- this.newTitle = newTitle;
- }
- public String getNewAuther() {
- return this.newAuther;
- }
- public void setNewAuther(String newAuther) {
- this.newAuther = newAuther;
- }
- public String getNewType() {
- return this.newType;
- }
- public void setNewType(String newType) {
- this.newType = newType;
- }
- public String getNewContent() {
- return this.newContent;
- }
- public void setNewContent(String newContent) {
- this.newContent = newContent;
- }
- }
PO类,MyEclipse 5.1.1生成:
java 代码
- package com.fzfx88.conf;
- // Generated by MyEclipse - Hibernate Tools
- /**
- * AjaxNew generated by MyEclipse - Hibernate Tools
- * auther huguoqing
- */
- public class AjaxNew extends AbstractAjaxNew implements java.io.Serializable {
- // Constructors
- /** default constructor */
- public AjaxNew() {
- }
- /** full constructor */
- public AjaxNew(String newTitle, String newAuther, String newType, String newContent) {
- super(newTitle, newAuther, newType, newContent);
- }
- }
Hibernate AjaxNew.hbm.xml配置文件
xml 代码
- <!---->xml version="1.0"?>
- <!---->
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!---->
- <hibernate-mapping>
- <class name="com.fzfx88.conf.AjaxNew" table="AJAX_NEW" schema="dbo" catalog="pepsi">
- <id name="id" type="java.lang.Integer">
- <column name="ID" />
- <generator class="identity" />
- id>
- <property name="newTitle" type="java.lang.String">
- <column name="NEW_TITLE" length="100" />
- property>
- <property name="newAuther" type="java.lang.String">
- <column name="NEW_AUTHER" length="30" />
- property>
- <property name="newType" type="java.lang.String">
- <column name="NEW_TYPE" length="30" />
- property>
- <property name="newContent" type="java.lang.String">
- <column name="NEW_CONTENT" length="500" />
- property>
- class>
- hibernate-mapping>
step:4 构建 Action 类:
java 代码
- /**
- * news system
- */
- package com.fzfx88.base.action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import com.fzfx88.base.form.AjaxNewsSystemForm;
- import com.fzfx88.base.service.AjaxNewsSystemService;
- import com.fzfx88.common.base.BaseAction;
- import com.fzfx88.conf.AjaxNew;
- /**
- * @author huguoqing
- *
- */
- public class AjaxNewsSystemAction extends BaseAction {
- AjaxNewsSystemService nService = new AjaxNewsSystemService();
- /**
- * 初始化
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward init(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- AjaxNewsSystemForm nForm = (AjaxNewsSystemForm)form;
- AjaxNew news = nForm.getNews();
- return mapping.findForward("init");
- }
- /**
- * 新建
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward save(ActionMapping mapping,ActionForm form,
- HttpServletRequest request,HttpServletResponse response){
- AjaxNewsSystemForm nForm = (AjaxNewsSystemForm)form;
- AjaxNew news = nForm.getNews();
- if(nService.createNews(news)){
- return mapping.findForward("success");
- }else{
- return mapping.findForward("false");
- }
- }
- }
step 5: 构建数据层访问类:
java 代码
- /**
- *
- */
- package com.fzfx88.base.service;
- import java.util.ArrayList;
- import java.util.List;
- import org.hibernate.Hibernate;
- import org.hibernate.HibernateException;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import com.fzfx88.conf.AjaxNew;
- import com.fzfx88.util.HibernateUtil;
- /**
- * @author huguoqing
- *
- */
- public class AjaxNewsSystemService {
- /**
- * 新建news
- * @param news
- */
- public boolean createNews(AjaxNew news){
- Session session=HibernateUtil.currentSession();
- Transaction tran=session.beginTransaction();
- try{
- session.save(news);
- tran.commit();
- session.flush();
- } catch (HibernateException e) {
- if(tran!=null){
- tran.rollback();
- }
- e.printStackTrace();
- return false;
- }finally {
- HibernateUtil.closeSession();
- }
- return true;
- }
- /**
- * 获得新闻列表
- * @param newType
- * @return
- */
- public List queryStoreList(String newType){
- List storeList =new ArrayList();
- Session session=HibernateUtil.currentSession();
- Transaction tran=session.beginTransaction();
- String sql="from AjaxNew where newType=:newType ";
- try {
- Query query=session.createQuery(sql);
- query.setParameter("newType",newType);
- storeList=query.list();
- } catch (HibernateException e) {
- if(tran!=null){
- tran.rollback();
- }
- e.printStackTrace();
- }finally {
- HibernateUtil.closeSession();
- }
- return storeList;
- }
- /**
- * 根据id获得AjaxNew对象
- * @param id
- * @return
- */
- public AjaxNew retrieveAjaxNew(String newId){
- Integer id = Integer.parseInt(newId);
- Session session=HibernateUtil.currentSession();
- String sql="from AjaxNew w where w.id=:id ";
- AjaxNew item=null;
- try {
- Query query=session.createQuery(sql);
- query.setParameter("id",id);
- item=(AjaxNew)query.uniqueResult();
- if(Hibernate.isInitialized(item)){
- Hibernate.initialize(item);
- }
- } catch (HibernateException e) {
- e.printStackTrace();
- }finally {
- HibernateUtil.closeSession();
- }
- return item;
- }
- }
step 6: 构建Struts Form .................AjaxNewsSystemForm.java
step 7 :Struts 配置文件:
xml 代码
- <!---->xml version="1.0" encoding="UTF-8"?>
- <!---->>
- <struts-config>
- <data-sources/>
- <form-beans>
- <form-bean name="AjaxNewsSystemForm" type="com.fzfx88.base.form.AjaxNewsSystemForm" />
- form-beans>
- <global-exceptions />
- <global-forwards>
- <forward name="success" path="/regSuccess.htm"/>
- <forward name="false" path="/false.htm"/>
- global-forwards>
- <action-mappings>
- <action name="AjaxNewsSystemForm"
- path="/news"
- type="com.fzfx88.base.action.AjaxNewsSystemAction"
- scope="request">
- <forward name="init" path="/base/news.jsp"/>
- action>
- action-mappings>
- <message-resources parameter="resource.ApplicationResources" />
- struts-config>
- ajaxtest.rar (2.3 MB)
- 下载次数: 1126
相关推荐
在本实例中,"DWR 应用实例(一) 新闻发布系统,多种新闻类型之间切换无刷新",我们将探讨如何使用DWR构建一个新闻发布系统,这个系统可以在用户选择不同新闻类型时,动态加载对应的内容,而无需重新加载整个页面。...
DWR是一种JavaScript库,它允许Web应用程序在客户端与服务器之间进行实时通信,实现了AJAX(Asynchronous JavaScript and XML)的核心功能,从而提供更流畅的用户体验。 在描述中提到的“dwr无刷新分页实例代码”,...
DWR支持多种数据类型在客户端和服务器之间自动转换,包括基本类型、集合、数组和自定义对象。此外,DWR还可以处理异步调用,这意味着用户界面可以在等待服务器响应的同时继续执行其他操作,提高了应用的响应速度。 ...
这是一个基于Java Web开发的小型留言板应用实例,使用了Maven作为构建工具,SSM(Spring、SpringMVC、MyBatis)作为核心框架,Proxool作为连接池,Freemarker作为视图模板引擎,DWR(Direct Web Remoting)用于实现...
DWR(Direct Web Remoting)是一个开源Java库,它允许Web应用程序在客户端JavaScript和服务器端Java之间进行直接的远程调用。这个“dwr.rar_dwr”文件很可能包含了一个DWR的实例,以及一个用于演示AJAX...
4. **自动类型转换**:DWR自动处理Java和JavaScript之间的数据类型转换,简化了数据交换过程。 5. **批量调用**:DWR支持批量调用多个服务器端方法,减少了网络往返次数,提高了性能。 Spring框架是Java企业级应用...
**DWR (Direct Web Remoting)** 是一个开源的Java库,它允许Web应用程序在客户端(浏览器)和服务器之间进行实时的、双向的通信,而无需使用插件或框架。DWR使得JavaScript能够直接调用服务器端的Java方法,极大地...
2. **Direct Web Remoting (DWR)**: DWR是一种JavaScript库,用于在浏览器和服务器之间进行异步通信,实现了JavaScript对象与Java方法之间的直接调用,类似于AJAX。这使得前端可以实时地与后端进行数据交换,无需...
这些实例覆盖了从简单的交互改进到复杂的功能增强,比如无刷新显示回帖、输入内容前的提示、带进度的文件上传、大量数据的动态浏览查询、信息排序以及标签页的切换等。 #### 二、无刷新显示回帖 **2.1 无刷新显示...