﻿<?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/f6k66ve/category/44049.html</link><description>遇高山，我御风而翔，逢江河，我凌波微波</description><language>zh-cn</language><lastBuildDate>Wed, 23 May 2012 21:59:56 GMT</lastBuildDate><pubDate>Wed, 23 May 2012 21:59:56 GMT</pubDate><ttl>60</ttl><item><title>java中断点续传</title><link>http://www.blogjava.net/f6k66ve/archive/2012/05/23/378940.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Wed, 23 May 2012 07:13:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2012/05/23/378940.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/378940.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2012/05/23/378940.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/378940.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/378940.html</trackback:ping><description><![CDATA[<p>转载自 <a href="http://www.ibm.com/developerworks/cn/java/joy-down/">http://www.ibm.com/developerworks/cn/java/joy-down/</a><a name="1"><span class="atitle"><br /><br />断点续传的原理</span></a></p>
<p>其实断点续传的原理很简单，就是在 Http 的请求上和一般的下载有所不同而已。 <br />打个比方，浏览器请求服务器上的一个文时，所发出的请求如下： <br />假设服务器域名为 wwww.sjtu.edu.cn，文件名为 down.zip。 <br />GET /down.zip HTTP/1.1 <br />Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms- <br />excel, application/msword, application/vnd.ms-powerpoint, */* <br />Accept-Language: zh-cn <br />Accept-Encoding: gzip, deflate <br />User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) <br />Connection: Keep-Alive </p>
<p>服务器收到请求后，按要求寻找请求的文件，提取文件的信息，然后返回给浏览器，返回信息如下：</p>
<p>200 <br />Content-Length=106786028 <br />Accept-Ranges=bytes <br />Date=Mon, 30 Apr 2001 12:56:11 GMT <br />ETag=W/"02ca57e173c11:95b" <br />Content-Type=application/octet-stream <br />Server=Microsoft-IIS/5.0 <br />Last-Modified=Mon, 30 Apr 2001 12:56:11 GMT </p>
<p>所谓断点续传，也就是要从文件已经下载的地方开始继续下载。所以在客户端浏览器传给 Web 服务器的时候要多加一条信息 -- 从哪里开始。 <br />下面是用自己编的一个"浏览器"来传递请求信息给 Web 服务器，要求从 2000070 字节开始。 <br />GET /down.zip HTTP/1.0 <br />User-Agent: NetFox <br />RANGE: bytes=2000070- <br />Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 </p>
<p>仔细看一下就会发现多了一行 RANGE: bytes=2000070- <br />这一行的意思就是告诉服务器 down.zip 这个文件从 2000070 字节开始传，前面的字节不用传了。 <br />服务器收到这个请求以后，返回的信息如下： <br />206 <br />Content-Length=106786028 <br />Content-Range=bytes 2000070-106786027/106786028 <br />Date=Mon, 30 Apr 2001 12:55:20 GMT <br />ETag=W/"02ca57e173c11:95b" <br />Content-Type=application/octet-stream <br />Server=Microsoft-IIS/5.0 <br />Last-Modified=Mon, 30 Apr 2001 12:55:20 GMT </p>
<p>和前面服务器返回的信息比较一下，就会发现增加了一行： <br />Content-Range=bytes 2000070-106786027/106786028 <br />返回的代码也改为 206 了，而不再是 200 了。 </p>
<p>知道了以上原理，就可以进行断点续传的编程了。 </p>
<div class="ibm-alternate-rule">
<hr />
</div>
<p class="ibm-ind-link ibm-back-to-top"><a class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/java/joy-down/#ibm-pcon">回页首</a></p>
<p><a name="2"><span class="atitle">Java 实现断点续传的关键几点</span></a></p>
<ol><li>(1) 用什么方法实现提交 RANGE: bytes=2000070-。 <br />当然用最原始的 Socket 是肯定能完成的，不过那样太费事了，其实 Java 的 net 包中提供了这种功能。代码如下： <br /><br />URL url = new URL("http://www.sjtu.edu.cn/down.zip"); <br />HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection(); <br /><br />// 设置 User-Agent <br />httpConnection.setRequestProperty("User-Agent","NetFox"); <br />// 设置断点续传的开始位置 <br />httpConnection.setRequestProperty("RANGE","bytes=2000070"); <br />// 获得输入流 <br />InputStream input = httpConnection.getInputStream(); <br />
<p>从输入流中取出的字节流就是 down.zip 文件从 2000070 开始的字节流。大家看，其实断点续传用 Java 实现起来还是很简单的吧。接下来要做的事就是怎么保存获得的流到文件中去了。 </p></li><li>保存文件采用的方法。 <br />我采用的是 IO 包中的 RandAccessFile 类。 <br />操作相当简单，假设从 2000070 处开始保存文件，代码如下： <br />RandomAccess oSavedFile = new RandomAccessFile("down.zip","rw"); <br />long nPos = 2000070; <br />// 定位文件指针到 nPos 位置 <br />oSavedFile.seek(nPos); <br />byte[] b = new byte[1024]; <br />int nRead; <br />// 从输入流中读入字节流，然后写到文件中 <br />while((nRead=input.read(b,0,1024)) &gt; 0) <br />{ <br />oSavedFile.write(b,0,nRead); <br />} <br /></li></ol>
<p>怎么样，也很简单吧。接下来要做的就是整合成一个完整的程序了。包括一系列的线程控制等等。 </p>
<div class="ibm-alternate-rule">
<hr />
</div>
<p><a name="3"><span class="atitle">断点续传内核的实现</span></a></p>
<p>主要用了 6 个类，包括一个测试类。 <br />SiteFileFetch.java 负责整个文件的抓取，控制内部线程 (FileSplitterFetch 类 )。 <br />FileSplitterFetch.java 负责部分文件的抓取。 <br />FileAccess.java 负责文件的存储。 <br />SiteInfoBean.java 要抓取的文件的信息，如文件保存的目录，名字，抓取文件的 URL 等。 <br />Utility.java 工具类，放一些简单的方法。 <br />TestMethod.java 测试类。 <br /></p>
<p>下面是源程序：</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td class="code-outline"><pre class="displaycode">/* 
 /*
 * SiteFileFetch.java 
 */ 
 package NetFox; 
 import java.io.*; 
 import java.net.*; 
 public class SiteFileFetch extends Thread { 
 SiteInfoBean siteInfoBean = null; // 文件信息 Bean 
 long[] nStartPos; // 开始位置
 long[] nEndPos; // 结束位置
 FileSplitterFetch[] fileSplitterFetch; // 子线程对象
 long nFileLength; // 文件长度
 boolean bFirst = true; // 是否第一次取文件
 boolean bStop = false; // 停止标志
 File tmpFile; // 文件下载的临时信息
 DataOutputStream output; // 输出到文件的输出流
 public SiteFileFetch(SiteInfoBean bean) throws IOException 
 { 
 siteInfoBean = bean; 
 //tmpFile = File.createTempFile ("zhong","1111",new File(bean.getSFilePath())); 
 tmpFile = new File(bean.getSFilePath()+File.separator + bean.getSFileName()+".info");
 if(tmpFile.exists ()) 
 { 
 bFirst = false; 
 read_nPos(); 
 } 
 else 
 { 
 nStartPos = new long[bean.getNSplitter()]; 
 nEndPos = new long[bean.getNSplitter()]; 
 } 
 } 
 public void run() 
 { 
 // 获得文件长度
 // 分割文件
 // 实例 FileSplitterFetch 
 // 启动 FileSplitterFetch 线程
 // 等待子线程返回
 try{ 
 if(bFirst) 
 { 
 nFileLength = getFileSize(); 
 if(nFileLength == -1) 
 { 
 System.err.println("File Length is not known!"); 
 } 
 else if(nFileLength == -2) 
 { 
 System.err.println("File is not access!"); 
 } 
 else 
 { 
 for(int i=0;i&lt;nStartPos.length;i++) 
 { 
 nStartPos[i] = (long)(i*(nFileLength/nStartPos.length)); 
 } 
 for(int i=0;i&lt;nEndPos.length-1;i++) 
 { 
 nEndPos[i] = nStartPos[i+1]; 
 } 
 nEndPos[nEndPos.length-1] = nFileLength; 
 } 
 } 
 // 启动子线程
 fileSplitterFetch = new FileSplitterFetch[nStartPos.length]; 
 for(int i=0;i&lt;nStartPos.length;i++) 
 { 
 fileSplitterFetch[i] = new FileSplitterFetch(siteInfoBean.getSSiteURL(), 
 siteInfoBean.getSFilePath() + File.separator + siteInfoBean.getSFileName(), 
 nStartPos[i],nEndPos[i],i); 
 Utility.log("Thread " + i + " , nStartPos = " + nStartPos[i] + ", nEndPos = " 
 + nEndPos[i]); 
 fileSplitterFetch[i].start(); 
 } 
 // fileSplitterFetch[nPos.length-1] = new FileSplitterFetch(siteInfoBean.getSSiteURL(),
 siteInfoBean.getSFilePath() + File.separator 
 + siteInfoBean.getSFileName(),nPos[nPos.length-1],nFileLength,nPos.length-1); 
 // Utility.log("Thread " +(nPos.length-1) + ",nStartPos = "+nPos[nPos.length-1]+",
 nEndPos = " + nFileLength); 
 // fileSplitterFetch[nPos.length-1].start(); 
 // 等待子线程结束
 //int count = 0; 
 // 是否结束 while 循环
 boolean breakWhile = false; 
 while(!bStop) 
 { 
 write_nPos(); 
 Utility.sleep(500); 
 breakWhile = true; 
 for(int i=0;i&lt;nStartPos.length;i++) 
 { 
 if(!fileSplitterFetch[i].bDownOver) 
 { 
 breakWhile = false; 
 break; 
 } 
 } 
 if(breakWhile) 
 break; 
 //count++; 
 //if(count&gt;4) 
 // siteStop(); 
 } 
 System.err.println("文件下载结束！"); 
 } 
 catch(Exception e){e.printStackTrace ();} 
 } 
 // 获得文件长度
 public long getFileSize() 
 { 
 int nFileLength = -1; 
 try{ 
 URL url = new URL(siteInfoBean.getSSiteURL()); 
 HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection ();
 httpConnection.setRequestProperty("User-Agent","NetFox"); 
 int responseCode=httpConnection.getResponseCode(); 
 if(responseCode&gt;=400) 
 { 
 processErrorCode(responseCode); 
 return -2; //-2 represent access is error 
 } 
 String sHeader; 
 for(int i=1;;i++) 
 { 
 //DataInputStream in = new DataInputStream(httpConnection.getInputStream ()); 
 //Utility.log(in.readLine()); 
 sHeader=httpConnection.getHeaderFieldKey(i); 
 if(sHeader!=null) 
 { 
 if(sHeader.equals("Content-Length")) 
 { 
 nFileLength = Integer.parseInt(httpConnection.getHeaderField(sHeader)); 
 break; 
 } 
 } 
 else 
 break; 
 } 
 } 
 catch(IOException e){e.printStackTrace ();} 
 catch(Exception e){e.printStackTrace ();} 
 Utility.log(nFileLength); 
 return nFileLength; 
 } 
 // 保存下载信息（文件指针位置）
 private void write_nPos() 
 { 
 try{ 
 output = new DataOutputStream(new FileOutputStream(tmpFile)); 
 output.writeInt(nStartPos.length); 
 for(int i=0;i&lt;nStartPos.length;i++) 
 { 
 // output.writeLong(nPos[i]); 
 output.writeLong(fileSplitterFetch[i].nStartPos); 
 output.writeLong(fileSplitterFetch[i].nEndPos); 
 } 
 output.close(); 
 } 
 catch(IOException e){e.printStackTrace ();} 
 catch(Exception e){e.printStackTrace ();} 
 } 
 // 读取保存的下载信息（文件指针位置）
 private void read_nPos() 
 { 
 try{ 
 DataInputStream input = new DataInputStream(new FileInputStream(tmpFile)); 
 int nCount = input.readInt(); 
 nStartPos = new long[nCount]; 
 nEndPos = new long[nCount]; 
 for(int i=0;i&lt;nStartPos.length;i++) 
 { 
 nStartPos[i] = input.readLong(); 
 nEndPos[i] = input.readLong(); 
 } 
 input.close(); 
 } 
 catch(IOException e){e.printStackTrace ();} 
 catch(Exception e){e.printStackTrace ();} 
 } 
 private void processErrorCode(int nErrorCode) 
 { 
 System.err.println("Error Code : " + nErrorCode); 
 } 
 // 停止文件下载
 public void siteStop() 
 { 
 bStop = true; 
 for(int i=0;i&lt;nStartPos.length;i++) 
 fileSplitterFetch[i].splitterStop(); 
 } 
 } 
 </pre></td></tr></tbody></table><br />
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td class="code-outline"><pre class="displaycode"> /* 
 **FileSplitterFetch.java 
 */ 
 package NetFox; 
 import java.io.*; 
 import java.net.*; 
 public class FileSplitterFetch extends Thread { 
 String sURL; //File URL 
 long nStartPos; //File Snippet Start Position 
 long nEndPos; //File Snippet End Position 
 int nThreadID; //Thread's ID 
 boolean bDownOver = false; //Downing is over 
 boolean bStop = false; //Stop identical 
 FileAccessI fileAccessI = null; //File Access interface 
 public FileSplitterFetch(String sURL,String sName,long nStart,long nEnd,int id)
 throws IOException 
 { 
 this.sURL = sURL; 
 this.nStartPos = nStart; 
 this.nEndPos = nEnd; 
 nThreadID = id; 
 fileAccessI = new FileAccessI(sName,nStartPos); 
 } 
 public void run() 
 { 
 while(nStartPos &lt; nEndPos &amp;&amp; !bStop) 
 { 
 try{ 
 URL url = new URL(sURL); 
 HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection (); 
 httpConnection.setRequestProperty("User-Agent","NetFox"); 
 String sProperty = "bytes="+nStartPos+"-"; 
 httpConnection.setRequestProperty("RANGE",sProperty); 
 Utility.log(sProperty); 
 InputStream input = httpConnection.getInputStream(); 
 //logResponseHead(httpConnection); 
 byte[] b = new byte[1024]; 
 int nRead; 
 while((nRead=input.read(b,0,1024)) &gt; 0 &amp;&amp; nStartPos &lt; nEndPos 
 &amp;&amp; !bStop) 
 { 
 nStartPos += fileAccessI.write(b,0,nRead); 
 //if(nThreadID == 1) 
 // Utility.log("nStartPos = " + nStartPos + ", nEndPos = " + nEndPos); 
 } 
 Utility.log("Thread " + nThreadID + " is over!"); 
 bDownOver = true; 
 //nPos = fileAccessI.write (b,0,nRead); 
 } 
 catch(Exception e){e.printStackTrace ();} 
 } 
 } 
 // 打印回应的头信息
 public void logResponseHead(HttpURLConnection con) 
 { 
 for(int i=1;;i++) 
 { 
 String header=con.getHeaderFieldKey(i); 
 if(header!=null) 
 //responseHeaders.put(header,httpConnection.getHeaderField(header)); 
 Utility.log(header+" : "+con.getHeaderField(header)); 
 else 
 break; 
 } 
 } 
 public void splitterStop() 
 { 
 bStop = true; 
 } 
 } 
 
 /* 
 **FileAccess.java 
 */ 
 package NetFox; 
 import java.io.*; 
 public class FileAccessI implements Serializable{ 
 RandomAccessFile oSavedFile; 
 long nPos; 
 public FileAccessI() throws IOException 
 { 
 this("",0); 
 } 
 public FileAccessI(String sName,long nPos) throws IOException 
 { 
 oSavedFile = new RandomAccessFile(sName,"rw"); 
 this.nPos = nPos; 
 oSavedFile.seek(nPos); 
 } 
 public synchronized int write(byte[] b,int nStart,int nLen) 
 { 
 int n = -1; 
 try{ 
 oSavedFile.write(b,nStart,nLen); 
 n = nLen; 
 } 
 catch(IOException e) 
 { 
 e.printStackTrace (); 
 } 
 return n; 
 } 
 } 
 
 /* 
 **SiteInfoBean.java 
 */ 
 package NetFox; 
 public class SiteInfoBean { 
 private String sSiteURL; //Site's URL 
 private String sFilePath; //Saved File's Path 
 private String sFileName; //Saved File's Name 
 private int nSplitter; //Count of Splited Downloading File 
 public SiteInfoBean() 
 { 
 //default value of nSplitter is 5 
 this("","","",5); 
 } 
 public SiteInfoBean(String sURL,String sPath,String sName,int nSpiltter)
 { 
 sSiteURL= sURL; 
 sFilePath = sPath; 
 sFileName = sName; 
 this.nSplitter = nSpiltter; 
 } 
 public String getSSiteURL() 
 { 
 return sSiteURL; 
 } 
 public void setSSiteURL(String value) 
 { 
 sSiteURL = value; 
 } 
 public String getSFilePath() 
 { 
 return sFilePath; 
 } 
 public void setSFilePath(String value) 
 { 
 sFilePath = value; 
 } 
 public String getSFileName() 
 { 
 return sFileName; 
 } 
 public void setSFileName(String value) 
 { 
 sFileName = value; 
 } 
 public int getNSplitter() 
 { 
 return nSplitter; 
 } 
 public void setNSplitter(int nCount) 
 { 
 nSplitter = nCount; 
 } 
 } 
 
 /* 
 **Utility.java 
 */ 
 package NetFox; 
 public class Utility { 
 public Utility() 
 { 
 } 
 public static void sleep(int nSecond) 
 { 
 try{ 
 Thread.sleep(nSecond); 
 } 
 catch(Exception e) 
 { 
 e.printStackTrace (); 
 } 
 } 
 public static void log(String sMsg) 
 { 
 System.err.println(sMsg); 
 } 
 public static void log(int sMsg) 
 { 
 System.err.println(sMsg); 
 } 
 } 
 
 /* 
 **TestMethod.java 
 */ 
 package NetFox; 
 public class TestMethod { 
 public TestMethod() 
 { ///xx/weblogic60b2_win.exe 
 try{ 
 SiteInfoBean bean = new SiteInfoBean("http://localhost/xx/weblogic60b2_win.exe",
     "L:\\temp","weblogic60b2_win.exe",5); 
 //SiteInfoBean bean = new SiteInfoBean("http://localhost:8080/down.zip","L:\\temp",
     "weblogic60b2_win.exe",5); 
 SiteFileFetch fileFetch = new SiteFileFetch(bean); 
 fileFetch.start(); 
 } 
 catch(Exception e){e.printStackTrace ();} 
 } 
 public static void main(String[] args) 
 { 
 new TestMethod(); 
 } 
 }
</pre></td></tr></tbody></table><br /><!-- CMA ID: 53173 --><!-- Site ID: 10 --><!-- XSLT stylesheet used to transform this file: dw-document-html-6.0.xsl --><br /><img src ="http://www.blogjava.net/f6k66ve/aggbug/378940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2012-05-23 15:13 <a href="http://www.blogjava.net/f6k66ve/archive/2012/05/23/378940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ajax+Flash多文件上传之 FancyUpload的应用</title><link>http://www.blogjava.net/f6k66ve/archive/2010/06/07/322974.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Mon, 07 Jun 2010 07:46:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2010/06/07/322974.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/322974.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2010/06/07/322974.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/322974.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/322974.html</trackback:ping><description><![CDATA[<p style="text-indent: 24pt;"><span style="font-size: 12pt;">Ajax+Flash</span>多文件上传是一个开源的上传组件，名称是<span style="font-size: 12pt;">F</span>ancyUpload，其官方网址是：<a href="http://digitarald.de/project/fancyupload/">http://digitarald.de/project/fancyupload/</a>。这个组件仅仅是客户端的应用组件，即与任何服务器端的技术没有关系，服务器端可以采用任何后台技术（如JSP、Servlet、ASP<span>等）。应用该组件提供
给我们的最大的好处有如下几点（个人认为，呵呵）：<br />
</span></p>
1<span style="font-family: Wingdings;"><span style="font: 7pt 'Times New Roman';"> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </span></span>仅是客户端的应用组件，服务器端可以采用任何后台技术<span style="font-family: Wingdings;"><span style="font: 7pt 'Times New Roman';">&nbsp; </span></span>；<span style="font-family: Wingdings;"><br />
</span>2<span style="font-family: Wingdings;"> </span>可以同时选择多个文件进行上传；<span style="font-family: Wingdings;"><br />
</span><span style="font-family: Wingdings;">3<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>以队列的形式排列要上传的文件和其相关信息（如名称、大小等）；<span style="font-family: Wingdings;"><br />
4<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>可以设置要上传的文件个数、文件类型和文件大小；<span style="font-family: Wingdings;"><br />
5<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span></span>有上传进度显示， 直观，实用）；<span style="font-family: Wingdings;"><br />
6<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>上传的过程中可以随时取消要上传的文件；<span style="font-family: Wingdings;"><br />
7<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>平台独立性，由于使用flash<span>和
成熟的</span>AJAX框架（mootools）可以避免对特定浏览器和服务器依赖！<span style="font-family: Wingdings;"><br />
8<span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>使用简单，文件体积小！<span style="font-family: Wingdings;"><br />
9</span>&nbsp; 表单无须设置enctype="multipart/form-data"<span><br clear="all" />
</span>
<p><br />
</p>
<img src ="http://www.blogjava.net/f6k66ve/aggbug/322974.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2010-06-07 15:46 <a href="http://www.blogjava.net/f6k66ve/archive/2010/06/07/322974.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>仿网易多附件上传功能</title><link>http://www.blogjava.net/f6k66ve/archive/2010/06/04/322772.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Fri, 04 Jun 2010 09:12:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2010/06/04/322772.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/322772.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2010/06/04/322772.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/322772.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/322772.html</trackback:ping><description><![CDATA[转载于http://blog.csdn.net/sunyujia/archive/2008/06/15/2549347.aspx<br />
<br />
&lt;html&gt;&nbsp; &nbsp;<br />
&lt;head&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;title&gt;Add Files&lt;/title&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;style&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
a.addfile {&nbsp; &nbsp;<br />
&nbsp; <br />
background-image:url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);&nbsp; &nbsp;<br />
&nbsp; <br />
background-repeat:no-repeat;&nbsp; &nbsp;<br />
&nbsp; <br />
background-position:-823px -17px;&nbsp; &nbsp;<br />
&nbsp; <br />
display:block;&nbsp; &nbsp;<br />
&nbsp; <br />
float:left;&nbsp; &nbsp;<br />
&nbsp; <br />
height:20px;&nbsp; &nbsp;<br />
&nbsp; <br />
margin-top:-1px;&nbsp; &nbsp;<br />
&nbsp; <br />
position:relative;&nbsp; &nbsp;<br />
&nbsp; <br />
text-decoration:none;&nbsp; &nbsp;<br />
&nbsp; <br />
top:0pt;&nbsp; &nbsp;<br />
&nbsp; <br />
width:80px;&nbsp; &nbsp;<br />
&nbsp; <br />
}&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
input.addfile {&nbsp; &nbsp;<br />
&nbsp; <br />
/*left:-18px;*/ &nbsp;<br />
&nbsp; <br />
}&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
input.addfile {&nbsp; &nbsp;<br />
&nbsp; <br />
cursor:pointer !important;&nbsp; &nbsp;<br />
&nbsp; <br />
height:18px;&nbsp; &nbsp;<br />
&nbsp; <br />
left:-13px;&nbsp; &nbsp;<br />
&nbsp; <br />
filter:alpha(opacity=0);&nbsp;&nbsp; &nbsp;<br />
&nbsp; <br />
position:absolute;&nbsp; &nbsp;<br />
&nbsp; <br />
top:5px;&nbsp; &nbsp;<br />
&nbsp; <br />
width:1px;&nbsp; &nbsp;<br />
&nbsp; <br />
z-index: -1;&nbsp; &nbsp;<br />
&nbsp; <br />
}&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/style&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&lt;script type="text/javascript"&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
function MultiSelector(list_target, max)&nbsp; &nbsp;<br />
&nbsp; <br />
{&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; // Where to write the list&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; this.list_target = list_target;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; // How many elements?&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; this.count = 0;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; // How many elements?&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; this.id = 0;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; // Is there a maximum?&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; if (max)&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.max = max;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.max = -1;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; /** &nbsp;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; * Add a new file input element &nbsp;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; this.addElement = function(element)&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Make sure it's a file input element&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (element.tagName == 'INPUT' &amp;&amp; element.type == 'file')&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Element name -- what number am I?&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.name = 'file_' + this.id++;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add reference to this object&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.multi_selector = this;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // What to do when a file is selected&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.onchange = function()&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // New file input&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var new_element = document.createElement('input');&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_element.type = 'file';&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_element.size = 1;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_element.className = "addfile";&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add new element&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.insertBefore(new_element, this);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Apply 'update' to element&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.multi_selector.addElement(new_element);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Update list&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.multi_selector.addListRow(this);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Hide this: we can't use display:none because Safari doesn't like it&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.style.position = 'absolute';&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.style.left = '-1000px';&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // If we've reached maximum number, disable input element&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.max != -1 &amp;&amp; this.count &gt;= this.max)&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; element.disabled = true;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // File element counter&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.count++;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Most recent element&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.current_element = element;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This can only be applied to file input elements!&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert('Error: not a file input element');&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; /** &nbsp;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; * Add a new row to the list of files &nbsp;<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; this.addListRow = function(element)&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Row div&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var new_row = document.createElement('div');&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Delete button&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var new_row_button = document.createElement('input');&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row_button.type = 'button';&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row_button.value = 'Delete';&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // References&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row.element = element;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Delete function&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row_button.onclick = function()&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Remove element from form&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.element.parentNode.removeChild(this.parentNode.element);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Remove this row from the list&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.parentNode.removeChild(this.parentNode);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Decrement counter&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.element.multi_selector.count--;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Re-enable input element (if it's disabled)&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.element.multi_selector.current_element.disabled = false;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Appease Safari&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // without it Safari wants to reload the browser window&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // which nixes your already queued uploads&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Set row value&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row.innerHTML = element.value + " ";&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add button&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_row.appendChild(new_row_button);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add it to the list&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.list_target.appendChild(new_row);&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp;&nbsp;&nbsp; };&nbsp; &nbsp;<br />
&nbsp; <br />
};&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/script&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/head&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&lt;body&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
&lt;!-- This is the form --&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;form enctype="multipart/form-data" action="http://127.0.0.1:8080/zzgh/cx/upload.jsp" method="post"&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;!-- The file element -- NOTE: it has an ID --&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;a href="javascript:void(1==1);" class="addfile" style="cursor: default;" hidefocus="true"&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;input id="my_file_element" class="addfile" type="file" name="file_1" size="1" title="点击选择附件"&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/a&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;input type="submit" value="上 传"&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/form&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&nbsp; <br />
&nbsp; <br />
Files:&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;!-- This is where the output will appear --&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;div id="files_list" style="padding:5px;border:1px;border-style:solid;border-color:#0000ff;height:100px;width:600px;"&gt;&lt;/div&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;script&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;!-- Create an instance of the multiSelector class, pass it the output target and the max number of files --&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
var multi_selector = new MultiSelector(document.getElementById('files_list'), 100);&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;!-- Pass in the file element --&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
multi_selector.addElement(document.getElementById('my_file_element'));&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/script&gt;&nbsp; &nbsp;<br />
&lt;/body&gt;&nbsp; &nbsp;<br />
&nbsp; <br />
&lt;/html&gt;&nbsp; <br />
<br />
<br />
效果图如下：<br />
<br />
<img alt="" src="http://www.blogjava.net/images/blogjava_net/f6k66ve/111.jpg" height="176" width="265" /><br />
<br />
<img src ="http://www.blogjava.net/f6k66ve/aggbug/322772.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2010-06-04 17:12 <a href="http://www.blogjava.net/f6k66ve/archive/2010/06/04/322772.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSP应用导出Excel报表的简单实现以及中文乱码彻底解决（HTML） </title><link>http://www.blogjava.net/f6k66ve/archive/2010/05/12/320750.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Wed, 12 May 2010 14:06:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2010/05/12/320750.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/320750.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2010/05/12/320750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/320750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/320750.html</trackback:ping><description><![CDATA[<p align="left">一，先新建一个excel文件，调整格式（就是你所想要显示的格式），<br />
<strong>二，</strong>把刚才新建的excel文件令存为.html（demo.html）文件，<br />
三，新建一个jsp页面， 在该JSP页面头部设置response的ContentType为Excel格式 <br />
<span style="font-size: 18pt;">&lt;% response.setContentType("application/vnd.ms-excel;charset=GBK"); %&gt; <br />
</span>然后设置网页资料是以excel报表以线上浏览方式呈现或者是下载的方式呈现<br />
&lt;%<br />
/ /这行设定传送到前端浏览器时的档名为test1.xls&nbsp; 就是靠这一行，让前端浏览器以为接收到一个excel档&nbsp;<br />
&nbsp;//将网页资料以excel报表以线上浏览方式呈现 <br />
<span style="font-size: 18pt;">response.setHeader("Content-disposition","inline; filename=test1.xls");</span><br />
&nbsp;&nbsp; //将网页资料以下载的方式<br />
<span style="font-size: 18pt;">response.setHeader("Content-disposition","attachment; filename=test2.xls"); </span><br />
%&gt;<br />
然后把&nbsp;demo.html的源代码粘贴在jsp页面，如下<br />
</p>
<p>&lt;%@ page contentType="text/html; charset=GBK" %&gt;<br />
&lt;% <span style="font-size: 12pt;">response.setContentType("application/vnd.ms-excel;charset=GBK"); </span><br />
<span style="font-size: 12pt;">response.setHeader("Content-disposition","attachment; filename=test2.xls"); </span><br />
<br />
%&gt;<br />
&lt;!--以下为保持成html页面的excel的内容 demo.html页面--&gt;<br />
&lt;html xmlns:o="urn:schemas-microsoft-com:office:office"<br />
xmlns:x="urn:schemas-microsoft-com:office:excel"<br />
xmlns="http://www.w3.org/TR/REC-html40"&gt;</p>
<p>&lt;head&gt;<br />
&lt;meta http-equiv=Content-Type content="text/html; charset=gb2312"&gt;<br />
&lt;meta name=ProgId content=Excel.Sheet&gt;<br />
&lt;meta name=Generator content="Microsoft Excel 11"&gt;<br />
&lt;link rel=File-List href="qwe.files/filelist.xml"&gt;<br />
&lt;link rel=Edit-Time-Data href="qwe.files/editdata.mso"&gt;<br />
&lt;link rel=OLE-Object-Data href="qwe.files/oledata.mso"&gt;<br />
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;<br />
&nbsp;&lt;o:DocumentProperties&gt;<br />
&nbsp; &lt;o:Created&gt;1996-12-17T01:32:42Z&lt;/o:Created&gt;<br />
&nbsp; &lt;o:LastSaved&gt;2010-05-12T13:59:04Z&lt;/o:LastSaved&gt;<br />
&nbsp; &lt;o:Version&gt;11.9999&lt;/o:Version&gt;<br />
&nbsp;&lt;/o:DocumentProperties&gt;<br />
&nbsp;&lt;o:OfficeDocumentSettings&gt;<br />
&nbsp; &lt;o:RemovePersonalInformation/&gt;<br />
&nbsp;&lt;/o:OfficeDocumentSettings&gt;<br />
&lt;/xml&gt;&lt;![endif]--&gt;<br />
&lt;style&gt;<br />
&lt;!--table<br />
&nbsp;{mso-displayed-decimal-separator:"\.";<br />
&nbsp;mso-displayed-thousand-separator:"\,";}<br />
@page<br />
&nbsp;{margin:1.0in .75in 1.0in .75in;<br />
&nbsp;mso-header-margin:.5in;<br />
&nbsp;mso-footer-margin:.5in;}<br />
tr<br />
&nbsp;{mso-height-source:auto;<br />
&nbsp;mso-ruby-visibility:none;}<br />
col<br />
&nbsp;{mso-width-source:auto;<br />
&nbsp;mso-ruby-visibility:none;}<br />
br<br />
&nbsp;{mso-data-placement:same-cell;}<br />
.style0<br />
&nbsp;{mso-number-format:General;<br />
&nbsp;text-align:general;<br />
&nbsp;vertical-align:bottom;<br />
&nbsp;white-space:nowrap;<br />
&nbsp;mso-rotate:0;<br />
&nbsp;mso-background-source:auto;<br />
&nbsp;mso-pattern:auto;<br />
&nbsp;color:windowtext;<br />
&nbsp;font-size:12.0pt;<br />
&nbsp;font-weight:400;<br />
&nbsp;font-style:normal;<br />
&nbsp;text-decoration:none;<br />
&nbsp;font-family:宋体;<br />
&nbsp;mso-generic-font-family:auto;<br />
&nbsp;mso-font-charset:134;<br />
&nbsp;border:none;<br />
&nbsp;mso-protection:locked visible;<br />
&nbsp;mso-style-name:常规;<br />
&nbsp;mso-style-id:0;}<br />
td<br />
&nbsp;{mso-style-parent:style0;<br />
&nbsp;padding-top:1px;<br />
&nbsp;padding-right:1px;<br />
&nbsp;padding-left:1px;<br />
&nbsp;mso-ignore:padding;<br />
&nbsp;color:windowtext;<br />
&nbsp;font-size:12.0pt;<br />
&nbsp;font-weight:400;<br />
&nbsp;font-style:normal;<br />
&nbsp;text-decoration:none;<br />
&nbsp;font-family:宋体;<br />
&nbsp;mso-generic-font-family:auto;<br />
&nbsp;mso-font-charset:134;<br />
&nbsp;mso-number-format:General;<br />
&nbsp;text-align:general;<br />
&nbsp;vertical-align:bottom;<br />
&nbsp;border:none;<br />
&nbsp;mso-background-source:auto;<br />
&nbsp;mso-pattern:auto;<br />
&nbsp;mso-protection:locked visible;<br />
&nbsp;white-space:nowrap;<br />
&nbsp;mso-rotate:0;}<br />
ruby<br />
&nbsp;{ruby-align:left;}<br />
rt<br />
&nbsp;{color:windowtext;<br />
&nbsp;font-size:9.0pt;<br />
&nbsp;font-weight:400;<br />
&nbsp;font-style:normal;<br />
&nbsp;text-decoration:none;<br />
&nbsp;font-family:宋体;<br />
&nbsp;mso-generic-font-family:auto;<br />
&nbsp;mso-font-charset:134;<br />
&nbsp;mso-char-type:none;<br />
&nbsp;display:none;}<br />
--&gt;<br />
&lt;/style&gt;<br />
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;<br />
&nbsp;&lt;x:ExcelWorkbook&gt;<br />
&nbsp; &lt;x:ExcelWorksheets&gt;<br />
&nbsp;&nbsp; &lt;x:ExcelWorksheet&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:Name&gt;Sheet1&lt;/x:Name&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:WorksheetOptions&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:DefaultRowHeight&gt;285&lt;/x:DefaultRowHeight&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:CodeName&gt;Sheet1&lt;/x:CodeName&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:Selected/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:Panes&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:Pane&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:Number&gt;3&lt;/x:Number&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ActiveCol&gt;1&lt;/x:ActiveCol&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/x:Pane&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/x:Panes&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectObjects&gt;False&lt;/x:ProtectObjects&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectScenarios&gt;False&lt;/x:ProtectScenarios&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/x:WorksheetOptions&gt;<br />
&nbsp;&nbsp; &lt;/x:ExcelWorksheet&gt;<br />
&nbsp;&nbsp; &lt;x:ExcelWorksheet&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:Name&gt;Sheet2&lt;/x:Name&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:WorksheetOptions&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:DefaultRowHeight&gt;285&lt;/x:DefaultRowHeight&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:CodeName&gt;Sheet2&lt;/x:CodeName&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectObjects&gt;False&lt;/x:ProtectObjects&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectScenarios&gt;False&lt;/x:ProtectScenarios&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/x:WorksheetOptions&gt;<br />
&nbsp;&nbsp; &lt;/x:ExcelWorksheet&gt;<br />
&nbsp;&nbsp; &lt;x:ExcelWorksheet&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:Name&gt;Sheet3&lt;/x:Name&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;x:WorksheetOptions&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:DefaultRowHeight&gt;285&lt;/x:DefaultRowHeight&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:CodeName&gt;Sheet3&lt;/x:CodeName&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectObjects&gt;False&lt;/x:ProtectObjects&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;x:ProtectScenarios&gt;False&lt;/x:ProtectScenarios&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/x:WorksheetOptions&gt;<br />
&nbsp;&nbsp; &lt;/x:ExcelWorksheet&gt;<br />
&nbsp; &lt;/x:ExcelWorksheets&gt;<br />
&nbsp; &lt;x:WindowHeight&gt;4530&lt;/x:WindowHeight&gt;<br />
&nbsp; &lt;x:WindowWidth&gt;8505&lt;/x:WindowWidth&gt;<br />
&nbsp; &lt;x:WindowTopX&gt;480&lt;/x:WindowTopX&gt;<br />
&nbsp; &lt;x:WindowTopY&gt;120&lt;/x:WindowTopY&gt;<br />
&nbsp; &lt;x:AcceptLabelsInFormulas/&gt;<br />
&nbsp; &lt;x:ProtectStructure&gt;False&lt;/x:ProtectStructure&gt;<br />
&nbsp; &lt;x:ProtectWindows&gt;False&lt;/x:ProtectWindows&gt;<br />
&nbsp;&lt;/x:ExcelWorkbook&gt;<br />
&lt;/xml&gt;&lt;![endif]--&gt;<br />
&lt;/head&gt;</p>
<p>&lt;body link=blue vlink=purple&gt;</p>
<p>&lt;table x:str border=0 cellpadding=0 cellspacing=0 width=288 style='border-collapse:<br />
&nbsp;collapse;table-layout:fixed;width:216pt'&gt;<br />
&nbsp;&lt;col width=72 span=4 style='width:54pt'&gt;<br />
&nbsp;&lt;tr height=19 style='height:14.25pt'&gt;<br />
&nbsp; &lt;td height=19 width=72 style='height:14.25pt;width:54pt'&gt;全球&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;问问&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;ee&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;rr&lt;/td&gt;<br />
&nbsp;&lt;/tr&gt;<br />
&nbsp;&lt;tr height=19 style='height:14.25pt'&gt;<br />
&nbsp; &lt;td height=19 style='height:14.25pt'&gt;暗暗&lt;/td&gt;<br />
&nbsp; &lt;td&gt;ss&lt;/td&gt;<br />
&nbsp; &lt;td&gt;dd&lt;/td&gt;<br />
&nbsp; &lt;td&gt;ff&lt;/td&gt;<br />
&nbsp;&lt;/tr&gt;<br />
&nbsp;&lt;![if supportMisalignedColumns]&gt;<br />
&nbsp;&lt;tr height=0 style='display:none'&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;&lt;/td&gt;<br />
&nbsp; &lt;td width=72 style='width:54pt'&gt;&lt;/td&gt;<br />
&nbsp;&lt;/tr&gt;<br />
&nbsp;&lt;![endif]&gt;<br />
&lt;/table&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;<br />
<br />
<br />
中文问题：<br />
查看源代码时发现JSP文件中写死的中文为乱码，则在JSP文件头部添加一行<br />
&lt;%@ page contentType="text/html; charset=gb2312" %&gt;<br />
查看源代码时发现文字为中文，但是用Excel打开为乱码则在&lt;html&gt;与&lt;head&gt;中加入<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=GBK"&gt;<br />
</p>
<p align="left">在jsp页面中，要在excel中显示的内容可以从数据库中读取，在此就不做详细的介绍了</p>
<img src ="http://www.blogjava.net/f6k66ve/aggbug/320750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2010-05-12 22:06 <a href="http://www.blogjava.net/f6k66ve/archive/2010/05/12/320750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat 不显示目录列表（在没有默认文件的时候）</title><link>http://www.blogjava.net/f6k66ve/archive/2010/02/26/314025.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Fri, 26 Feb 2010 09:28:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2010/02/26/314025.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/314025.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2010/02/26/314025.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/314025.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/314025.html</trackback:ping><description><![CDATA[在tomcat的conf目录下找到web.xml，在里面查找 &nbsp; <br />
&nbsp; &lt;servlet&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;servlet-name&gt;default&lt;/servlet-name&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;servlet-class&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; org.apache.catalina.servlets.DefaultServlet &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/servlet-class&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;init-param&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-name&gt;debug&lt;/param-name&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-value&gt;0&lt;/param-value&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/init-param&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;init-param&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-name&gt;listings&lt;/param-name&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-value&gt;true&lt;/param-value&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/init-param&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/servlet&gt; &nbsp; <br />
&nbsp; 把里面的 &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;init-param&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-name&gt;listings&lt;/param-name&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;param-value&gt;true&lt;/param-value&gt; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/init-param&gt; &nbsp; <br />
&nbsp; true改为false
 <img src ="http://www.blogjava.net/f6k66ve/aggbug/314025.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2010-02-26 17:28 <a href="http://www.blogjava.net/f6k66ve/archive/2010/02/26/314025.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于web.xml中的&lt;welcome-file&gt;</title><link>http://www.blogjava.net/f6k66ve/archive/2010/02/26/askzs.html</link><dc:creator>askzs</dc:creator><author>askzs</author><pubDate>Fri, 26 Feb 2010 09:19:00 GMT</pubDate><guid>http://www.blogjava.net/f6k66ve/archive/2010/02/26/askzs.html</guid><wfw:comment>http://www.blogjava.net/f6k66ve/comments/314024.html</wfw:comment><comments>http://www.blogjava.net/f6k66ve/archive/2010/02/26/askzs.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/f6k66ve/comments/commentRss/314024.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/f6k66ve/services/trackbacks/314024.html</trackback:ping><description><![CDATA[<p>最近有个工程，需要把HnSp文件下的index.html作为默认页面（目录结构如下），<br />
</p>
<p><img height="66" alt="" src="http://www.blogjava.net/images/blogjava_net/f6k66ve/qq.jpg" width="149" border="0" /><br />
我在web.xml中设置&lt;welcome-file&gt;HnSp/index.html&lt;/welcome-file&gt;,可是前台index.html</p>
<p>能显示出来，可是页面中的图片都显示不出来（index.html中的图片的路径都是用的相对路</p>
<p>径），后来在发现显示的页面中的图片少了一级，在图片的路径前加入HnSp就能正确显示了</p>
<p>，可是在别的页面通过链接访问index.html页面，图片还是显示不出来，看了知道，多了个</p>
<p>HnSp，看来在图片的路径前加入HnSp是不对的，<br />
我一直想不懂为什么，后来想了个办法解决了，就是在WebRoot下新建一个新的空页面 </p>
<p>MyJspjsp，写入如下代码 &lt;%response.sendRedirect("HnSp/index.html"); %&gt;，然后把&nbsp;&nbsp;&nbsp; </p>
<p>&lt;welcome-file&gt;HnSp/index.html&lt;/welcome-file&gt;,改为&lt;welcome-</p>
<p>file&gt;MyJsp.jsp&lt;/welcome-file&gt;,这样问题就解决了，都不存在路径错误问题了，</p>
<p>response.sendRedirect() </p>
<p>是在用户的浏览器端工作,sendRedirect()可以带参数传递,比如servlet?name=frank传至下</p>
<p>个页面,同时它可以重定向至不同的主机上,sendRedirect()可以重定向有frame.的jsp文件.</p>
<p>重定向后在浏览器地址栏上会出现重定向页面的URL，由于response是jsp页面中的隐含对象</p>
<p>，故在jsp页面中可以用response.sendRedirect()直接实现重定位。<br />
</p>
<img src ="http://www.blogjava.net/f6k66ve/aggbug/314024.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/f6k66ve/" target="_blank">askzs</a> 2010-02-26 17:19 <a href="http://www.blogjava.net/f6k66ve/archive/2010/02/26/askzs.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>