﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-Java随笔</title><link>http://www.blogjava.net/dragonjack/</link><description>Java知识，自己的随想，开发过程中的一些经验等。</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 07:52:12 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 07:52:12 GMT</pubDate><ttl>60</ttl><item><title>关于JSP中下载</title><link>http://www.blogjava.net/dragonjack/archive/2005/11/26/21499.html</link><dc:creator>寻觅</dc:creator><author>寻觅</author><pubDate>Sat, 26 Nov 2005 04:43:00 GMT</pubDate><guid>http://www.blogjava.net/dragonjack/archive/2005/11/26/21499.html</guid><wfw:comment>http://www.blogjava.net/dragonjack/comments/21499.html</wfw:comment><comments>http://www.blogjava.net/dragonjack/archive/2005/11/26/21499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dragonjack/comments/commentRss/21499.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dragonjack/services/trackbacks/21499.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最近的工作中涉及到了下载机能，在做的过程中遇到了下面一些问题。这些问题都已经解决了，但是对策肯定不是唯一，如果大家有好的对策，愿意共通研究。或者在下载过程中有什么其他需要注意的问题，敬请留言。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">1、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下载完毕后不能够重定向画面。这种情况是发生在使用了</SPAN><SPAN lang=EN-US>frameset</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的画面上。<BR></SPAN><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><STRONG>基本现象：</STRONG></SPAN><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">点击下载按钮，下载执行完毕后，再按其他的按钮，会出现</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">错误，不能够找到原来画面中的控件。原因就是因为下载完毕后不能够重定向到原来的画面。</SPAN><SPAN lang=EN-US><BR><BR></SPAN><STRONG><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">原因及对策</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN></STRONG><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交的时候把提交的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>target</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设定为</SPAN><SPAN lang=EN-US>top</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，这样下载完毕后，页面能够重定向，就不会出现</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码语法错误的现象。同时使用这种方法能够把下载过程中出现的错误信息显示在原来的画面上。此时需要注意一点，由于提交到的是</SPAN><SPAN lang=EN-US>top</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，所以出错返回的画面也要是整个</SPAN><SPAN lang=EN-US>frame</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的画面，同时还要保存原画面用户输入的数据，所以建议原来画面的数据使用</SPAN><SPAN lang=EN-US>session</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来保存。</SPAN><SPAN lang=EN-US><BR>function clickButton(){<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>form.target = “_top”<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>form.submit();<BR>}<BR><BR></SPAN><STRONG><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">原因及对策</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN></STRONG><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在当前页面添加一个内祯用于下载使用，提交下载的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的时候可以把</SPAN><SPAN lang=EN-US>target</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指定到内祯上，这样不会影响到原来画面，原画面可以继续操作。不过这种方法存在着弊端：一是很难使用</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">防止多重提交。二、如果下载过程中出现错误，显示错误信息比较麻烦。鉴于上述两种弊端使用这种方法一般是提交两次，第一次正常提交把要下载的数据准备好，保证下载能够正常进行，对于出错的处理也是在这一次进行的；第二次提交是提交到内祯，此次提交只是进行下载直接，不考虑会出现错误。这次提交是在</SPAN><SPAN lang=EN-US>onload</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中执行的。</SPAN><SPAN lang=EN-US><BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;iframe name="download" style=”<B> </B><SPAN style="mso-bidi-font-weight: bold">visibility:hidden</SPAN>”/&gt;<BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交的时候使用下面的</SPAN><SPAN lang=EN-US>javascript<BR>function clickButton(){<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>form.target = “download”;<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>form.submit();<BR>}</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><STRONG><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不正常的下载现象。</SPAN></STRONG><SPAN lang=EN-US><BR></SPAN><STRONG><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现象</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN></STRONG><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>windows2000</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作系统下，有时候点击下载，弹出下载对话框后点击打开，会再次弹出打开对话框。</SPAN><SPAN lang=EN-US><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><STRONG>原因及对策：</STRONG></SPAN><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这可能是</SPAN><SPAN lang=EN-US>IE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的安全设定产生的问题，如果要解决这个问题，也有办法。我在反复的试验中发现，出现这种现象的时候，提交下载的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的数据在</SPAN><SPAN lang=EN-US>server</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">端被用到，此时就会出现弹出两次对话框的现象，如果没有</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中没有数据或者</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的数据在</SPAN><SPAN lang=EN-US>server</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">端不会被使用，那么就不会有这种现象，所以</SPAN><SPAN lang=EN-US>download</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以设定一个空的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。（如果考虑到</SPAN><SPAN lang=EN-US>netscape</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">浏览器，</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面还要放上一个</SPAN><SPAN lang=EN-US>hidden</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件，否则</SPAN><SPAN lang=EN-US>netscape</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交不了。）这样这种现象就不会出现了。</SPAN><SPAN lang=EN-US><BR>&lt;form name=”mainForm”&gt;<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>&lt;input type=”button” name=”download” onclick=”clickButton()”&gt;<BR>&lt;/form&gt;<BR>&lt;form name=”downLoadForm”&gt;<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>&lt;input type=”hidden” name=”noUsed” /&gt;<BR>&lt;/form&gt;<BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用的</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如下：</SPAN><SPAN lang=EN-US><BR>function clickButton(){<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>downLoadForm.submit();<BR>}<BR><BR></SPAN><STRONG><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现象</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN></STRONG><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>windowsXP</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下，有时候下载会导致弹出安全制御的提示条。</SPAN><SPAN lang=EN-US><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><STRONG>原因及对策：</STRONG></SPAN><SPAN lang=EN-US><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我所遇到的这样的问题产生的原因是，我是用了</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的对策</SPAN><SPAN lang=EN-US>2,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在准备完毕数据后，在</SPAN><SPAN lang=EN-US>onload</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法中执行了提交到内祯的下载操作，结果出现了安全的提示条（页面最上端）。对策方法就是不在</SPAN><SPAN lang=EN-US>onload</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交下载的操作。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><STRONG><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">3、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有关下载的性能问题。</SPAN></STRONG></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 17.95pt; TEXT-INDENT: 21pt; mso-para-margin-left: 1.71gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果下载的是固定的文件一般不会有问题，我们可以通过</SPAN><SPAN lang=EN-US>File</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类的方法得到文件的长度，然后分次写入到流就可以了。但是有时候下载的内容可能动态组成的，比如说从数据库检索出来的等。在这种情况下，如果先从数据库中检索出所有的数据，然后在把数据按照下载的格式编辑出来，最后再算出长度分次写入到流中，性能肯定不高。为了提交性能，我们可以这样做，一次编辑一定数目的记录，然后就向流中写入，这样也是分次的写入到流中。在这种方式下，用户能够尽快看到下载的对话框，减少等待时间，同时也减少了下载过程中内存的使用量，提高了下载的性能。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上面三个问题是我在使用</SPAN><SPAN lang=EN-US>struts</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架做下载功能时遇到的一些问题，以及自己的一些对策，供大家参考如果大家有更好的解决办法，请赐教。</SPAN></P><img src ="http://www.blogjava.net/dragonjack/aggbug/21499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dragonjack/" target="_blank">寻觅</a> 2005-11-26 12:43 <a href="http://www.blogjava.net/dragonjack/archive/2005/11/26/21499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>发芽</title><link>http://www.blogjava.net/dragonjack/archive/2005/11/10/19232.html</link><dc:creator>寻觅</dc:creator><author>寻觅</author><pubDate>Thu, 10 Nov 2005 15:57:00 GMT</pubDate><guid>http://www.blogjava.net/dragonjack/archive/2005/11/10/19232.html</guid><wfw:comment>http://www.blogjava.net/dragonjack/comments/19232.html</wfw:comment><comments>http://www.blogjava.net/dragonjack/archive/2005/11/10/19232.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/dragonjack/comments/commentRss/19232.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dragonjack/services/trackbacks/19232.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 今天是第一次来到BlogJava这个博客网站，也是第一次正式的注册博客，希望在这个网站里面能够结交一些朋友，也希望自己的写的东西对大家能够有所帮助。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我是一名程序员，主要是作Java方面开发的，喜欢学习Java方面的技术，为了能够使自己能够更好的掌握Java方面的知识，我想通过博客把自己学习的一些想法记录下来，和各位交流一下，共同提高嘛！先谢谢诸位朋友了，以后还希望能够经常光顾我的博客，给出建议。<img src ="http://www.blogjava.net/dragonjack/aggbug/19232.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dragonjack/" target="_blank">寻觅</a> 2005-11-10 23:57 <a href="http://www.blogjava.net/dragonjack/archive/2005/11/10/19232.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>