随笔-95  评论-31  文章-10  trackbacks-0
  2010年1月18日
     摘要: Jdk和cglib动态代理说明和示例  阅读全文
posted @ 2018-08-16 10:46 朔望魔刃 阅读(187) | 评论 (0)编辑 收藏
     摘要: 简化resultMap映射  阅读全文
posted @ 2018-03-14 13:58 朔望魔刃 阅读(939) | 评论 (0)编辑 收藏
     摘要: HTTP+Restful的常用安全认证策略  阅读全文
posted @ 2018-01-19 16:04 朔望魔刃 阅读(410) | 评论 (0)编辑 收藏
     摘要: spring对quartz的简单整合配置  阅读全文
posted @ 2017-12-27 18:18 朔望魔刃 阅读(2008) | 评论 (0)编辑 收藏
     摘要: 解决DIGEST-MD5, Not authcated 等问题  阅读全文
posted @ 2017-12-22 17:58 朔望魔刃 阅读(355) | 评论 (0)编辑 收藏
     摘要: 一点小结  阅读全文
posted @ 2017-12-18 22:32 朔望魔刃 阅读(264) | 评论 (0)编辑 收藏
     摘要: 简单优化  阅读全文
posted @ 2017-11-17 14:19 朔望魔刃 阅读(3158) | 评论 (0)编辑 收藏
     摘要: 一点吐槽  阅读全文
posted @ 2017-11-17 00:50 朔望魔刃 阅读(1086) | 评论 (0)编辑 收藏
     摘要: nativeQuery的坑  阅读全文
posted @ 2017-11-14 14:20 朔望魔刃 阅读(5550) | 评论 (0)编辑 收藏
     摘要: 延迟加载的深入理解  阅读全文
posted @ 2017-11-13 18:12 朔望魔刃 阅读(418) | 评论 (0)编辑 收藏
     摘要: page从0开始  阅读全文
posted @ 2017-11-10 11:06 朔望魔刃 阅读(187) | 评论 (0)编辑 收藏
     摘要: spring-boot 静态资源配置  阅读全文
posted @ 2017-11-08 14:31 朔望魔刃 阅读(595) | 评论 (0)编辑 收藏
     摘要: spring-boot文件上传同时包含Dto  阅读全文
posted @ 2017-10-19 13:28 朔望魔刃 阅读(1331) | 评论 (0)编辑 收藏
     摘要: K-邻近算法  阅读全文
posted @ 2017-08-01 12:02 朔望魔刃 阅读(135) | 评论 (0)编辑 收藏
     摘要: 机器学习入门-流程  阅读全文
posted @ 2017-08-01 11:47 朔望魔刃 阅读(286) | 评论 (0)编辑 收藏
     摘要: Nginx反向代理负载均衡以及端口丢失问题  阅读全文
posted @ 2017-07-15 15:01 朔望魔刃 阅读(2322) | 评论 (0)编辑 收藏
     摘要: 转换  阅读全文
posted @ 2017-06-13 10:13 朔望魔刃 阅读(448) | 评论 (0)编辑 收藏
     摘要: maven三种打包插件优劣对比  阅读全文
posted @ 2017-05-03 10:08 朔望魔刃 阅读(15084) | 评论 (0)编辑 收藏
     摘要: 启动问题  阅读全文
posted @ 2017-02-19 11:33 朔望魔刃 阅读(192) | 评论 (0)编辑 收藏
     摘要: 修改sqoop源码并部署配合oozie测试  阅读全文
posted @ 2016-12-09 13:42 朔望魔刃 阅读(576) | 评论 (0)编辑 收藏
     摘要: oozie sqoop hive 各种问题  阅读全文
posted @ 2016-12-06 17:45 朔望魔刃 阅读(1129) | 评论 (0)编辑 收藏
     摘要: 使用mvn deploy发布到远程仓库时报错 Return code is: 400  阅读全文
posted @ 2016-12-01 09:58 朔望魔刃 阅读(190) | 评论 (0)编辑 收藏
     摘要: oozie调度sqoop1  阅读全文
posted @ 2016-10-10 14:12 朔望魔刃 阅读(938) | 评论 (0)编辑 收藏
     摘要: oozie的server配置运行  阅读全文
posted @ 2016-09-21 18:01 朔望魔刃 阅读(320) | 评论 (0)编辑 收藏
     摘要: oozie安装及生成  阅读全文
posted @ 2016-09-21 13:38 朔望魔刃 阅读(852) | 评论 (0)编辑 收藏
     摘要: 安装配置mysql  阅读全文
posted @ 2015-12-21 20:42 朔望魔刃 阅读(258) | 评论 (0)编辑 收藏
JPA
     摘要: 1+N的问题  阅读全文
posted @ 2015-07-20 17:04 朔望魔刃 阅读(324) | 评论 (0)编辑 收藏
     摘要: maven添加额外目录或者资源  阅读全文
posted @ 2015-07-16 12:58 朔望魔刃 阅读(726) | 评论 (0)编辑 收藏
     摘要: 打包  阅读全文
posted @ 2015-05-13 18:14 朔望魔刃 阅读(292) | 评论 (0)编辑 收藏
     摘要: 配置关键点  阅读全文
posted @ 2015-02-16 13:47 朔望魔刃 阅读(284) | 评论 (0)编辑 收藏
     摘要: 血与泪的教训之一坨翔  阅读全文
posted @ 2015-02-15 11:57 朔望魔刃 阅读(260) | 评论 (0)编辑 收藏
     摘要: maven自定义构建多模块工程  阅读全文
posted @ 2015-02-12 00:43 朔望魔刃 阅读(2165) | 评论 (0)编辑 收藏
     摘要: 配置以及解决不能创建django工程的问题  阅读全文
posted @ 2015-01-19 15:29 朔望魔刃 阅读(206) | 评论 (0)编辑 收藏
     摘要: windows访问linux远程桌面,免费工具  阅读全文
posted @ 2014-12-20 22:13 朔望魔刃 阅读(269) | 评论 (0)编辑 收藏
     摘要: Ivy问题  阅读全文
posted @ 2014-12-10 10:40 朔望魔刃 阅读(228) | 评论 (0)编辑 收藏
     摘要: 事物复习  阅读全文
posted @ 2014-07-17 14:06 朔望魔刃 阅读(332) | 评论 (0)编辑 收藏
     摘要: 简单架构图以及自定义协议分析  阅读全文
posted @ 2014-05-21 00:21 朔望魔刃 阅读(5928) | 评论 (0)编辑 收藏
     摘要: 联想网卡设置,解决网速慢以及连接不上问题  阅读全文
posted @ 2014-05-16 22:43 朔望魔刃 阅读(8502) | 评论 (0)编辑 收藏
     摘要: netty用法  阅读全文
posted @ 2014-05-05 15:17 朔望魔刃 阅读(2269) | 评论 (0)编辑 收藏
     摘要: netty初体验  阅读全文
posted @ 2014-05-03 14:11 朔望魔刃 阅读(5444) | 评论 (0)编辑 收藏
     摘要: spring4.0.2整合blazeds+flex  阅读全文
posted @ 2014-03-10 15:37 朔望魔刃 阅读(3911) | 评论 (0)编辑 收藏
     摘要: 结构与行为  阅读全文
posted @ 2013-09-30 15:08 朔望魔刃 阅读(250) | 评论 (0)编辑 收藏
     摘要: 存储  阅读全文
posted @ 2013-09-28 14:57 朔望魔刃 阅读(246) | 评论 (0)编辑 收藏
     摘要: 行为,行为  阅读全文
posted @ 2013-09-26 16:34 朔望魔刃 阅读(244) | 评论 (0)编辑 收藏
     摘要:   阅读全文
posted @ 2013-09-26 13:57 朔望魔刃 阅读(209) | 评论 (0)编辑 收藏
     摘要: 类的friend  阅读全文
posted @ 2013-09-24 15:34 朔望魔刃 阅读(237) | 评论 (0)编辑 收藏
     摘要: eclipse部署  阅读全文
posted @ 2013-09-23 13:59 朔望魔刃 阅读(2484) | 评论 (0)编辑 收藏
     摘要: 单用户以及群组移植  阅读全文
posted @ 2013-08-01 12:02 朔望魔刃 阅读(1625) | 评论 (0)编辑 收藏
     摘要: 集群配置  阅读全文
posted @ 2013-07-25 15:40 朔望魔刃 阅读(9821) | 评论 (17)编辑 收藏
     摘要: 配置运行  阅读全文
posted @ 2013-07-22 15:09 朔望魔刃 阅读(2834) | 评论 (0)编辑 收藏
     摘要: root无法登录以及linux安装服务后远程无法访问端口  阅读全文
posted @ 2013-07-18 13:26 朔望魔刃 阅读(17807) | 评论 (1)编辑 收藏
     摘要: JTable绘制单元格颜色  阅读全文
posted @ 2013-04-27 21:00 朔望魔刃 阅读(2001) | 评论 (0)编辑 收藏
     摘要: 还有rpc的osgi工程的jar包依赖  阅读全文
posted @ 2012-07-25 01:37 朔望魔刃 阅读(2478) | 评论 (0)编辑 收藏
     摘要: 不是我玩osgi 是osgi玩我  阅读全文
posted @ 2012-07-25 00:51 朔望魔刃 阅读(452) | 评论 (0)编辑 收藏
     摘要: 值传递是什么?其实很简单  阅读全文
posted @ 2012-06-13 22:07 朔望魔刃 阅读(267) | 评论 (0)编辑 收藏
     摘要: 最终类初始化顺序  阅读全文
posted @ 2012-06-13 21:52 朔望魔刃 阅读(228) | 评论 (0)编辑 收藏
     摘要: 基础知识  阅读全文
posted @ 2012-06-12 20:31 朔望魔刃 阅读(304) | 评论 (0)编辑 收藏
     摘要: 温故而知新,说自己不浮躁 其实自己还是浮躁  阅读全文
posted @ 2012-06-12 00:12 朔望魔刃 阅读(279) | 评论 (0)编辑 收藏
     摘要: swing日期控件  阅读全文
posted @ 2012-05-24 20:40 朔望魔刃 阅读(6826) | 评论 (0)编辑 收藏
     摘要: swing小结  阅读全文
posted @ 2012-05-23 21:22 朔望魔刃 阅读(232) | 评论 (0)编辑 收藏
     摘要: hibernate  阅读全文
posted @ 2012-01-18 12:41 朔望魔刃 阅读(265) | 评论 (0)编辑 收藏
try
     摘要: try  阅读全文
posted @ 2011-12-14 21:03 朔望魔刃 阅读(200) | 评论 (0)编辑 收藏
     摘要: 简单数据结构  阅读全文
posted @ 2011-12-07 12:40 朔望魔刃 阅读(248) | 评论 (0)编辑 收藏
     摘要: 生产者消费者  阅读全文
posted @ 2011-11-09 22:04 朔望魔刃 阅读(210) | 评论 (0)编辑 收藏
     摘要: 区别  阅读全文
posted @ 2011-11-05 11:04 朔望魔刃 阅读(198) | 评论 (0)编辑 收藏
     摘要: socket及web  阅读全文
posted @ 2011-09-04 13:21 朔望魔刃 阅读(247) | 评论 (0)编辑 收藏
     摘要: 一个赋值  阅读全文
posted @ 2011-06-02 17:52 朔望魔刃 阅读(185) | 评论 (0)编辑 收藏
     摘要: xfire基本用法  阅读全文
posted @ 2011-05-30 17:48 朔望魔刃 阅读(539) | 评论 (0)编辑 收藏
     摘要: 如题  阅读全文
posted @ 2011-03-28 21:05 朔望魔刃 阅读(5388) | 评论 (0)编辑 收藏
     摘要: 如题  阅读全文
posted @ 2011-03-17 02:26 朔望魔刃 阅读(329) | 评论 (1)编辑 收藏
     摘要: 如题  阅读全文
posted @ 2011-03-10 15:07 朔望魔刃 阅读(5281) | 评论 (3)编辑 收藏
     摘要: Axis2使用  阅读全文
posted @ 2011-03-04 17:08 朔望魔刃 阅读(2960) | 评论 (0)编辑 收藏
     摘要: 浮  阅读全文
posted @ 2011-02-28 18:15 朔望魔刃 阅读(166) | 评论 (0)编辑 收藏
     摘要: 如题  阅读全文
posted @ 2011-02-16 16:25 朔望魔刃 阅读(3302) | 评论 (0)编辑 收藏
     摘要: 命令模式中的关键点  阅读全文
posted @ 2010-12-25 23:28 朔望魔刃 阅读(238) | 评论 (0)编辑 收藏
     摘要: Java IO里面类层次记忆  阅读全文
posted @ 2010-12-25 23:06 朔望魔刃 阅读(198) | 评论 (0)编辑 收藏
     摘要: linux环境下tomcat配置若干问题  阅读全文
posted @ 2010-09-17 16:35 朔望魔刃 阅读(1600) | 评论 (0)编辑 收藏
     摘要: Google了一下午,思考了一下午,终于找到解决办法。。。其实原来很简单~  阅读全文
posted @ 2010-09-17 00:04 朔望魔刃 阅读(5647) | 评论 (1)编辑 收藏
     摘要: 基于下载、以及多个链接使用同一个Action方法的注解  阅读全文
posted @ 2010-09-09 18:49 朔望魔刃 阅读(2281) | 评论 (0)编辑 收藏
     摘要: ORACLE常见命令总结,都是工作中常用的  阅读全文
posted @ 2010-09-08 20:46 朔望魔刃 阅读(729) | 评论 (0)编辑 收藏
这个问题本身说起来就很纠结,一般都只会配置多个数据源即多个数据库,很少有配置多个表空间的,其实hibernate根本不需要配置任何表空间,只需使用MyEclipse的MyEclipse hibernate视图进行映射表生成pojo即可,唯一需要改动的只是赋予一个用户访问多个表空间的权限即可,使用sys用户dba身份登陆plsql输入:alter user 用户 quota unlimited on 表空间A; 就可以使一个用户访问多个表空间了,那么当执行hql语句的时候,会自动跟上表空间名字进行访问查询。
posted @ 2010-09-08 20:40 朔望魔刃 阅读(2284) | 评论 (0)编辑 收藏
     摘要: struts2  阅读全文
posted @ 2010-09-07 23:45 朔望魔刃 阅读(372) | 评论 (0)编辑 收藏
     摘要: /** *//**  * @author LX  * 通用Reveiver类  */ public abstract class Receiver {          //抽象接收者,定义每个接收...  阅读全文
posted @ 2010-09-06 23:42 朔望魔刃 阅读(250) | 评论 (0)编辑 收藏
     摘要: 命令模式  阅读全文
posted @ 2010-09-06 00:21 朔望魔刃 阅读(268) | 评论 (0)编辑 收藏
     摘要: 不一样的单例模式,虽然很简单但是再次理解有了不一样的认识。。。  阅读全文
posted @ 2010-09-02 15:44 朔望魔刃 阅读(355) | 评论 (1)编辑 收藏
     摘要: 该模式挺难理解,想了快一晚上。。。才算有点眉目。。。然后照搬一些java.io类还有servlet里面的过滤器终于有所领悟。 使用接口实现,下面给出代码:   1/** *//**   2 *定义被装饰者   3 **/   4public interface&nb...  阅读全文
posted @ 2010-08-31 11:07 朔望魔刃 阅读(2324) | 评论 (1)编辑 收藏

第一种适用于:20100823这种字符串格式

function dateValid(){
    var bd 
= document.getElementById("sStartSaveDate").value;
    var beginDate 
=  new Date(bd.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1/$2/$3"));
    
    var ed 
= document.getElementById("sEndSaveDate").value;
    var endDate 
= new Date(ed.replace(/^(\d{4})(\d{2})(\d{2})$/,"$1/$2/$3"));
    
    
if(beginDate >= endDate){
        alert(
"结束时间必须大于开始时间!");
        
return false;
    }
else{
        document.getElementById(
'searchform').submit(); 
    }

}
第二种适用于:2010-08-23这种字符串格式
function dateValid(){
    var beginDate 
=  new Date(document.getElementById("sStartSaveDate").value.replace(/-/g,"/"));
    var endDate 
= new Date(document.getElementById("sEndSaveDate").value.replace(/-/g,"/"));
    
if(beginDate >= endDate){
        alert(
"结束时间必须大于开始时间!");
        
return false;
    }
else{
     document.getElementById(
'searchform').submit();
}


第三种适用于:2010/08/23这种字符串格式
function dateValid(){
    var beginDate 
=  new Date(document.getElementById("sStartSaveDate").value);
    var endDate 
= new Date(document.getElementById("sEndSaveDate").value);
    
if(beginDate >= endDate){
        alert(
"结束时间必须大于开始时间!");
        
return false;
    }
else{
     document.getElementById(
'searchform').submit();
}

}

posted @ 2010-08-23 19:20 朔望魔刃 阅读(2732) | 评论 (1)编辑 收藏
     摘要: 熟悉代理模式的基础上,首先使用反射实现动态调用某个对象的某个方法,目的就是某个对象某个方法可以进行配置,使用XML或者使用后缀名properties文件。 代码如下:   1import java.lang.reflect.Method   2public class ReflectUtils{   ...  阅读全文
posted @ 2010-08-19 10:33 朔望魔刃 阅读(479) | 评论 (0)编辑 收藏
     摘要:  1public class MyStack {  2    private int[] a;  3    private int count = 0;  4  &...  阅读全文
posted @ 2010-08-19 10:19 朔望魔刃 阅读(225) | 评论 (0)编辑 收藏

经验不足导致了N多问题~特此总结下
1、首先确认双方建立长连接OR短连接,这问题由于双方缺乏沟通头痛了好久。对方其实是短连接,而自己用长连接方式发送导致消息漏发。
2、其次确认每条消息开始结束符,双方互相确认,以此为依据进行分隔消息进行处理。使用了(char)11和(char)28作为每条消息的开始结束符,对方是0x0b和0x1c,其实就是(char)11和(char)28。
3、发送紧急数据判断是否和对方处于连接状态也就是网络上流传的心跳数据每次发送消息前即java这边socket.sendUrgentData(0)来判断。使用socket.isClosed()和socket.isConnected();判断是否连接不起作用!这个只能判断之前的连接是否还处于连接状态。
4、编码问题对方使用UTF-8 java这边是GBK,使用InputStreamWriter来进行输出编码设置。

posted @ 2010-04-02 13:26 朔望魔刃 阅读(1340) | 评论 (1)编辑 收藏

客户端使用java
服务端使用C#

客户端数据库SqlServer2000编码简体中文GBK
服务端数据库SqlServer2008编码SQL_Latin1_General_CP1_CI_AS

客户端取出数据使用new String("消息".getBytes("GBK"),"UTF-8");进行转换
发送的时候使用PrintWriter pw = new PrintWriter(socket.getOutputStream);
服务端只接收UTF-8编码显示为乱码。

后来参考资料,才明白new String("消息".getBytes("GBK"),"UTF-8");这种方式只是在JVM内部转换,那么一旦涉及到流比如数据库、文件等就要使用java IO进行转换。也就是说JVM内部编码unicode和外部os编码的转换。
使用下面方式就没有问题了
字符流方式发送
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream),"UTF-8")),false);
字节流方式发送
PrintStream ps = new PrintStream(socket.getOutputStream(),false,"UTF-8");
false表示手动pw.flush();

posted @ 2010-03-18 21:18 朔望魔刃 阅读(1559) | 评论 (0)编辑 收藏
首先下载java service wrapper工具
http://sourceforge.net/project/showfiles.php?group_id=39428

步骤:
1、解压缩java service wrapper包,假设目录为:wrapper_home
2、建立一个目录比如:D盘server文件夹里面建立bin、conf、logs、lib文件夹。
3、将wrapper_home/bin目录里wrapper.exe
   将wrapper_home/src/bin目录里App.bat.in
   将wrapper_home/src/bin目录里InstallApp-NT.bat.in
   将wrapper_home/src/bin目录里UninstallApp-NT.bat.in
   统一拷贝至server/bin目录里,并去掉后缀名in。
   将wrapper_home/src/conf目录wrapper.conf.in拷贝至server/conf目录里去掉后缀名in
   再将wrapper_home/lib/目录里面的wrapper.jar和wrapper.dll拷贝至server/lib目录里面
4、将你的应用程序打成jar包后放入server/lib目录里面,如果程序依赖第三方架包,同样将jar包放入该目录下。
5、配置server/conf/wrapper.conf文件。
主要修改以下几项即可:
#你的JVM位置:
wrapper.java.command=%JAVA_HOME%\bin\java
#classpath:里面添加上你要执行的应用程序jar,以及依赖的第三方jar,有多个依次类推
wrapper.java.classpath.1=../lib/应用程序.jar
wrapper.java.classpath.2=../lib/wrapper.jar
wrapper.java.classpath.3=../bin/第三方.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS 此处决定了使用Java Service Wrapper的方式
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
上面红色字体不能修改成你的执行程序路径比如
service.server.Serverbegin 否则打成服务后启动会提示如下错误:

ERROR  | wrapper  | 2010/01/07 15:13:10 | JVM did not exit on request, terminated
STATUS | wrapper  | 2010/01/07 15:13:15 | Launching a JVM...
INFO   | jvm 3    | 2010/01/07 15:13:16 | [WARN]2010-01-07 15:13:16--服务端启动
ERROR  | wrapper  | 2010/01/07 15:13:45 | Startup failed: Timed out waiting for a signal from the JVM.
ADVICE | wrapper  | 2010/01/07 15:13:45 | 
ADVICE | wrapper  | 2010/01/07 15:13:45 | ------------------------------------------------------------------------
ADVICE | wrapper  | 2010/01/07 15:13:45 | Advice:
ADVICE | wrapper  | 2010/01/07 15:13:45 | The Wrapper consists of a native component as well as a set of classes
ADVICE | wrapper  | 2010/01/07 15:13:45 | which run within the JVM that it launches.  The Java component of the
ADVICE | wrapper  | 2010/01/07 15:13:45 | Wrapper must be initialized promptly after the JVM is launched or the
ADVICE | wrapper  | 2010/01/07 15:13:45 | Wrapper will timeout, as just happened.  Most likely the main class
ADVICE | wrapper  | 2010/01/07 15:13:45 | specified in the Wrapper configuration file is not correctly initializing
ADVICE | wrapper  | 2010/01/07 15:13:45 | the Wrapper classes:
ADVICE | wrapper  | 2010/01/07 15:13:45 |     service.hl7Server.HuaHaiHl7Server
ADVICE | wrapper  | 2010/01/07 15:13:45 | While it is possible to do so manually, the Wrapper ships with helper
ADVICE | wrapper  | 2010/01/07 15:13:45 | classes to make this initialization processes automatic.
ADVICE | wrapper  | 2010/01/07 15:13:45 | Please review the integration section of the Wrapper's documentation
ADVICE | wrapper  | 2010/01/07 15:13:45 | for the various methods which can be employed to launch an application
ADVICE | wrapper  | 2010/01/07 15:13:45 | within the Wrapper:
ADVICE | wrapper  | 2010/01/07 15:13:45 |     http://wrapper.tanukisoftware.org/doc/english/integrate.html
#你的Java应用类,
wrapper.app.parameter.1= service.Server.Serverbegin
# 服务名
wrapper.ntservice.name=server
# Display name of the service
wrapper.ntservice.displayname=server
# 服务描述
wrapper.ntservice.description=receive message
其他的配置根据你的需要改变即可
6.  对以上配置的App.bat进行测试,运行App.bat,dos窗口中显示;
7.  对以上配置的服务进行测试,运行server/bin/InstallApp-NT.bat将把你的应用(此处为server)安装到Win32系统服务中了。
8.  打开控制面板-管理程序-服务,看到server已经在系统服务中了,其他用法就与我们熟悉的Windows服务一样了。

bin/App.bat  控制台方式运行程序

bin/InstallApp-NT.bat  安装服务

bin/UninstallApp-NT.bat 删除服务
posted @ 2010-01-18 13:10 朔望魔刃 阅读(3389) | 评论 (2)编辑 收藏
网上流传了大量大量的如何导出,结果都不太实用。
网上流传通用的js导出word代码如下:
     function method1(){
      var oWD = new ActiveXObject("Word.Application"); 
      oWD.WindowState = 2; 
      var oDC = oWD.Documents.Add("",0,1); 
      var oRange =oDC.Range(0,1); 
      var sel = document.body.createTextRange(); 
      sel.moveToElementText(huahai);  //里面参数为div的id或者form的id或者table的id或者...表示将此范围内输出word
      sel.select(); 
      sel.execCommand("Copy"); 
      oRange.Paste(); 
      oWD.Application.Visible = true; 
      }
<body>
<div id="huahai">
</div>
</body>
<input type="button" onclick="javascript:method1();" value="导出为WORD">
以上方法可导出任意jsp(包括图片)但是除了以下内容:
凡是让用户输入带有<input>或者<textarea>等等等标签输入框地方就不能导出成word了。
比如一个table(如下所示),如果使用上述办法就不能导出。
如果去掉<input>标签那么就可以导出,但是问题就是我就是要全部导出.......
<table id="table1">
<tr>
<td>姓名</td><td><input type="text" size="5"></td>
<td>年龄</td><td><input type="text" size="5"></td>
</tr>
<table>
解决办法:
下面给出一个JSP,里面包含div、form、table、image、以及各种<input>标签导出为word
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<form action="" id="huahai" >
  <div align="center">
   <div align="center" id="div_content">
    <h2>
     <font color="red">测试导出word</font>
    </h2>
    <h4>
     <font color="red">测试导出word</font>
    </h4>
    </div>
<table id="table1">
<tr>
<td>姓名</td><td><input type="text" size="5"></td>
<td>年龄</td><td><input type="text" size="5"></td>
</tr>
<table>
<div id="img">
    <hr/>
    <img src="MM.jpg" height="45%" width="30%">
    </br>
</div>
 <div id="text_area">
    <textarea name="warn_task" wrap="off" cols="80" rows="12">区域内容:</textarea>
    </textarea>
    <hr />
</div>
<input type="button" onclick="javascript:test();" value="测试">
</div>
 </form>
</body>
</html>
下面给出js代码(加入<head>标签之间):
<script type="text/javascript">
   var oWD = new ActiveXObject("Word.Application");
   var oDC = oWD.Documents.Add("",0,1);
   var oRange =oDC.Range(0,1);
function word(id,way){
   var sel = document.body.createTextRange();
   sel.moveToElementText(id);
   sel.select();
   sel.execCommand(way);
   oRange.Paste();
}

function test(){
   var table=document.getElementById('table1');
   var table_cells = table.rows[0].cells;
   var form_elements = document.getElementById('huahai');
   word(div_content,'Copy'); //调用word函数,将div_content范围内容拷贝到word里面。
   for(i=0;i<table_cells.length;i++){
       oRange =oDC.Range(oRange.End-1,oRange.End); //设定位置依次由上往下、从左往右
       var sel = document.body.createTextRange();
       sel.moveToElementText(table_cells[i]); //将单元格内容复制到word
       sel.select();
       sel.execCommand("Copy");
       sel.moveEnd('character');  //不加这句导出不了,里面参数为character、不是copy
       oRange.Paste();
       oRange =oDC.Range(oRange.End-1,oRange.End);
   }
    oRange =oDC.Range(oRange.End-1,oRange.End); //复制不同的东西,需要写这句继续 写死的这句话就是位置
    var img = document.getElementById('img');
    word(img,'Copy');//将img范围内容拷贝到word里面。
    oRange =oDC.Range(oRange.End-1,oRange.End);
    var text_area = document.getElementById('text_area');
    word(text_area,'Copy');//将text_area范围内容拷贝到word里面。
    oRange =oDC.Range(oRange.End-1,oRange.End);
    oWD.Application.Visible = true; //这句意思是所有操作完毕后,在显示出来,如果写在里面,会发现word打开后,什么标签啊、内容啊就跟打字机一样往里面填
}
</script>
 
最后补充:IE工具设置,安全--启动-对没有标记为安全的Activex的控件进行初始化和脚本运行
posted @ 2010-01-18 13:04 朔望魔刃 阅读(6086) | 评论 (2)编辑 收藏