??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲AV一二三区成人影片,亚洲中文字幕成人在线,另类小说亚洲色图http://www.tkk7.com/FOG/zh-cnSat, 10 May 2025 19:10:04 GMTSat, 10 May 2025 19:10:04 GMT60 commons-fileupload q?/title><link>http://www.tkk7.com/FOG/archive/2009/12/03/304611.html</link><dc:creator>FOG</dc:creator><author>FOG</author><pubDate>Thu, 03 Dec 2009 05:46:00 GMT</pubDate><guid>http://www.tkk7.com/FOG/archive/2009/12/03/304611.html</guid><wfw:comment>http://www.tkk7.com/FOG/comments/304611.html</wfw:comment><comments>http://www.tkk7.com/FOG/archive/2009/12/03/304611.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/FOG/comments/commentRss/304611.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/FOG/services/trackbacks/304611.html</trackback:ping><description><![CDATA[  <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Java Web</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">开发h员可以?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg来接收浏览器上传的文Ӟ该组件由多个cd同组成,但是Q对于用该lg来编写文件上传功能的</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Java Web</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">开发h员来_只需要了解和使用其中的三个类Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">。这三个cd部位?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">org.apache.commons.fileupload</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">包中?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">查看</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文档</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">在准备实验环境时获得?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">commons-fileupload-1.0.zip</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g的解压羃目录中可以看C?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">docs</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">的子目录Q其中包含了</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg中的各个</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ帮助文Q从q个文中可以了解到各个</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ使用帮助信息。打开文g上传lg</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">帮助文档中的</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">index.html</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">面Q在左侧分栏H口面中列Z文g上传lg中的各个</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ名称Q在右侧分栏H口面的底部列Z一D늤例代码,如图</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">所C?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.2</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">读者不需要逐个去阅d</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中列出的各个</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ帮助文Q而应该以?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的CZ代码为线索,以其中所使用到的cMؓ入口点,按图索骥地进行阅读,对于CZ代码中调用到的各?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">API</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝҎ则应重点掌握?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><br /> <br /> <strong><span style="font-family: Verdana">1. DiskFileUpload</span></strong></span><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">c?/span></strong></p> <p style="background: white; line-height: 150%"><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">cL</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">文g上传lg的核心类Q应用程序开发h员通过q个cL?/span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">文g上传lgq行交互。但现在</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">使用</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ServletFileUpload</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">c?/span></strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q两个类的方法类伹{下面介l?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cM的几个常用的重要Ҏ?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.1</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeMax</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeMax</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于讄h消息实体内容的最大允许大,以防止客L故意通过上传特大的文件来塞满服务器端的存储空_单位为字节。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">     public void setSizeMax</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">long sizeMax</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">如果h消息中的实体内容的大超q了</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeMax</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的设||该方法将会抛?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">异常?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeThreshold</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg在解析和处理上传数据中的每个字段内容Ӟ需要时保存解析出的数据。因?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Java</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">虚拟机默认可以用的内存I间是有限的Q笔者测试不大于</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">100M</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q,出限制时将会发?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“java.lang.OutOfMemoryError”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">错误Q如果上传的文g很大Q例如上?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">800M</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">的文Ӟ在内存中无法保存该文g内容Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg用临时文g来保存这些数据;但如果上传的文g很小Q例如上?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">600</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">个字节的文gQ显然将其直接保存在内存中更加有效?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeThreshold</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于讄是否使用临时文g保存解析出的数据的那个界|该方法传入的参数的单位是字节。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public void setSizeThreshold(int sizeThreshold)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3. setRepositoryPath</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setRepositoryPath</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于讄</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setSizeThreshold</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ中提到的临时文g的存攄录,q里要求使用l对路径。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public void setRepositoryPath(String repositoryPath)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">如果不设|存放\径,那么临时文g被储存?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">"java.io.tmpdir"</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">q个</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">JVM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">环境属性所指定的目录中Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">tomcat 5.5.9</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">这个属性设|ؓ?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“<tomcat</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">安装目录</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">>/temp/”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">目录?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.4. parseRequest</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ重要ҎQ它是对</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">HTTP</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">h消息q行解析的入口方法,如果h消息中的实体内容的类型不?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“multipart/form-data”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q该Ҏ抛?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">异常?/span><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest </span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">Ҏ解析?/span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">表单中的每个字段的数据,q将它们分别包装成独立的</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">对象Q然后将q些</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">对象加入q一?/span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">List</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">cd的集合对象中q回?/span></strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public List parseRequest(HttpServletRequest req)</span></strong></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏq有一个重载方法,该方法集中处理上q所有方法的功能Q其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest(HttpServletRequest req,int sizeThreshold,long sizeMax,</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">             String path)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">q两?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">parseRequest</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ都会抛出</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">异常?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.5. isMultipartContent</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">isMultipartContent</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">ҎҎ用于判断h消息中的内容是否?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“multipart/form-data”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cdQ是则返?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">true</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q否则返?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">false</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">isMultipartContent</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ是一个静态方法,不用创徏</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cȝ实例对象卛_被调用,其完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public static final boolean isMultipartContent(HttpServletRequest req)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.6. setHeaderEncoding</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">׃览器在提交</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单Ӟ会将普通表单中填写的文本内容传递给服务器,对于文g上传字段Q除了传递原始的文g内容外,q要传递其文g路径名等信息Q如后面的图</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">所C。不?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单采用的是</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“application/x-www-form-urlencoded”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">~码Q还?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“multipart/form-data”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">~码Q它们仅仅是各?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单字段元素内容l织CL一U格式,而这些内容又是由某种字符集编码来表示的。关于浏览器采用何种字符集来~码</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单字段中的内容Q请参看W者编著的《深入体?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">java Web</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">开发内q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">—?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">核心基础》一书中的第</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">6.9.2</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">的讲解,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“multipart/form-data”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd的表单ؓ表单字段内容选择字符集编码的原理和方式与</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“application/x-www-form-urlencoded”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd的表单是相同的?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单中填写的文本内容和文件上传字D中的文件\径名在内存中是它们的某U字W集~码的字节数lŞ式,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg在读取这些内ҎQ必ȝ道它们所采用的字W集~码Q才能将它们转换成正的字符文本q回?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对于览器上传给</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">WEB</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">服务器的各个表单字段的描q头内容Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg都需要将它们转换成字W串形式q回Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setHeaderEncoding </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于讄转换时所使用的字W集~码Q其原理与笔者编著的《深入体?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">java Web</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">开发内q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">—?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">核心基础》一书中的第</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">6.9.4</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">节讲解的</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ServletRequest.setCharacterEncoding</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ相同?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setHeaderEncoding </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public void setHeaderEncoding(String encoding)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">其中Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">encoding</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">参数用于指定各个表单字D늚描述头内容{换成字符串时所使用的字W集~码?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">注意Q如果读者在使用</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg旉C中文字符的ؕ码问题,一般都是没有正调?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">setHeaderEncoding</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的原因?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><br /> <br /> <strong><span style="font-family: Verdana">2. FileItem</span></strong></span><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">c?/span></strong></p> <p style="background: white; line-height: 150%"><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">cȝ来封装单个表单字D元素的数据Q一个表单字D元素对应一?/span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">对象Q通过调用</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">对象的方法可以获得相兌单字D元素的数据?/span></strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">是一个接口,在应用程序中使用的实际上是该接口一个实现类Q该实现cȝ名称q不重要Q程序可以采?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">接口cd来对它进行引用和讉KQؓ了便于讲解,q里?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">实现cȝ之ؓ</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cR?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">c还实现?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Serializable</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">接口Q以支持序列化操作?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对于</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“multipart/form-data”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FORM</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">表单Q浏览器上传的实体内容中的每个表单字D元素的数据之间用字D分隔界U进行分Ԍ两个分隔界线间的内容UCؓ一个分区,每个分区中的内容可以被看作两部分Q一部分是对表单字段元素q行描述的描q头Q另外一部是表单字段元素的主体内容,如图</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">所C?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"> 1.3</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">M部分有两U可能性,要么是用户填写的表单内容Q要么是文g内容?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象实际上是对图</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的一个分区的数据q行装的对象,它内部用了两个成员变量来分别存储描述头和M内容Q其中保存主体内容的变量是一个输出流cd的对象。当M内容的大小?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload.setSizeThreshold</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ讄的界值大时Q这个流对象兌C片内存,M内容会被保存在内存中。当M内容的数据超q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload.setSizeThreshold</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ讄的界值大时Q这个流对象兌到硬盘上的一个时文ӞM内容被保存到该临时文g中。时文件的存储目录?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">DiskFileUpload.setRepositoryPath</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ讄Q时文件名的格式ؓ</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“upload_00000005</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q八位或八位以上的数字)</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">.tmp”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">q种形式Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd部提供了l护临时文g名中的数g重复的机Ӟ以保证了临时文g名的唯一性。当应用E序主体内容保存到一个指定的文g中时Q或者在</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对象被垃圑֛收器回收Ӟ或?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Java</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">虚拟机结束时Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg都会试删除临时文gQ以量保证临时文g能被及时清除?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">下面介绍</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cM的几个常用的ҎQ?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.1. isFormField</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">isFormField</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于判断</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象封装的数据是否属于一个普通表单字D,q是属于一个文件表单字D,如果是普通表单字D则q回</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">true</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q否则返?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">false</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">。该Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public boolean isFormField()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.2. getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于获得文g上传字段中的文g名,对于?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的W三个分区所C的描述_</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏq回的结果ؓ字符?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“C:"bg.gif”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">。如?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象对应的是普通表单字D,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ返?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">null</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">。即使用h有通过|页表单中的文g字段传递Q何文Ӟ但只要设|了文g表单字段?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">name</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">属性,览器也会将文g字段的信息传递给服务器,只是文g名和文g内容部分都ؓI,但这个表单字D仍然对应一?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对象Q此Ӟ</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏq回l果为空字符?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">""</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q读者在调用</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lg时要注意考虑q个情况?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public String getName()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">注意Q如果用户?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Windows</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">pȝ上传文gQ浏览器传递该文g的完整\径,如果用户使用</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Linux</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">或?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Unix</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">pȝ上传文gQ浏览器只传递该文g的名U部分?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getFieldName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getFieldName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于q回表单字段元素?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">name</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">属性|也就是返回图</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的各个描述头部分中?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">name</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">属性|例如</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“name=p1”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“p1”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getFieldName</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public String getFieldName()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.4. write</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">write</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">Ҏ用于?/span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">对象中保存的M内容保存到某个指定的文g中?/span></strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">如果</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对象中的M内容是保存在某个临时文g中,该方法顺利完成后Q时文件有可能会被清除。该Ҏ也可普通表单字D内容写入到一个文件中Q但它主要用途是上传的文g内容保存在本地文件系l中。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public void write(File file)</span></strong></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.5</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getString</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">    getString</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">对象中保存的M内容作ؓ一个字W串q回Q它有两个重载的定义形式Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public java.lang.String getString()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public java.lang.String getString(java.lang.String encoding)</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">     throws java.io.UnsupportedEncodingException</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">前者用缺省的字符集编码将M内容转换成字W串Q后者用参数指定的字符集编码将M内容转换成字W串。如果在d普通表单字D元素的内容时出C中文q现象Q请调用W二?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getString</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">ҎQƈZ传递正的字符集编码名U?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.6. getContentType</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getContentType </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用于获得上传文g的类型,对于?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">1.3</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">中的W三个分区所C的描述_</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getContentType</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏq回的结果ؓ字符?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“image/gif”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q即</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">“Content-Type”</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">字段的值部分。如?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象对应的是普通表单字D,该方法将q回</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">null</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">getContentType </span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ的完整语法定义如下:</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public String getContentType()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.7. isInMemory</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">isInMemory</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用来判断</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象封装的M内容是存储在内存中,q是存储在时文件中Q如果存储在内存中则q回</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">true</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Q否则返?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">false</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public boolean isInMemory()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">2.8. delete</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">delete</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ用来清空</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileItem</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cd象中存放的主体内容,如果M内容被保存在临时文g中,</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">delete</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">Ҏ删除该临时文g。尽?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">lg使用了多U方式来量及时清理临时文gQ但pȝ出现异常Ӟ仍有可能造成有的临时文g被永久保存在了硬盘中。在有些情况下,可以调用q个Ҏ来及时删除时文件。其完整语法定义如下Q?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">public void delete()</span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><br /> <br /> <strong><span style="font-family: Verdana">3. FileUploadException</span></strong></span><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">c?/span></strong></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">在文件上传过E中Q可能发生各U各L异常Q例如网l中断、数据丢q{。ؓ了对不同异常q行合适的处理Q?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">文g上传lgq开发了四个异常c,其中</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">是其他异常类的父c,其他几个cd是被间接调用的底层类Q对?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">Apache</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">lg调用人员来说Q只需<strong><span style="font-family: 宋体">?/span></strong></span><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">FileUploadException</span></strong><strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: 宋体">异常c进行捕获和处理卛_</span></strong><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">?/span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana"><br /> <br /> <strong><span style="font-family: Verdana">4. ServletRequestContext</span></strong></span></p> <p style="background: white; line-height: 150%"><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">ServletRequestContext</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">cL供访?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">request</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">的方法。实?/span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%; font-family: Verdana">RequestContext</span><span style="font-size: 10pt; color: #4b4b4b; line-height: 150%">接口?/span></p> <img src ="http://www.tkk7.com/FOG/aggbug/304611.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/FOG/" target="_blank">FOG</a> 2009-12-03 13:46 <a href="http://www.tkk7.com/FOG/archive/2009/12/03/304611.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>prototype.js?/title><link>http://www.tkk7.com/FOG/archive/2009/11/30/304182.html</link><dc:creator>FOG</dc:creator><author>FOG</author><pubDate>Sun, 29 Nov 2009 16:14:00 GMT</pubDate><guid>http://www.tkk7.com/FOG/archive/2009/11/30/304182.html</guid><wfw:comment>http://www.tkk7.com/FOG/comments/304182.html</wfw:comment><comments>http://www.tkk7.com/FOG/archive/2009/11/30/304182.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.tkk7.com/FOG/comments/commentRss/304182.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/FOG/services/trackbacks/304182.html</trackback:ping><description><![CDATA[<div id="91h7z79" class="ns_content"> <p><a >prototype.js</a>是一个很强大的Javascript函数?它可以让你很L的用一些特?实现AJAX的功?虽然prototype.js是ؓ了Ruby On Rails开发的,它的UJavascript的性质也得它很容易用在其他的|络E序?可惜的是,Prototype.jsq没有强大的文解释,管它的代码非常有条?但是也给初学者造成了一定的ȝ.作者在README里说:</p> <p><em>Prototype is embarrassingly lacking in documentation. (The source code should be fairly easy to comprehend; I’m committed to using a clean style with meaningful identifiers. But I know that only goes so far.) </em></p> <pre>基本用法:以Element ClassZ,prototypel每个主要的分类都分成了一个Class,使用h很方?要生特定的效果的话只要用new Class.function(<argument>)可以了.比如:</pre> <pre><DIV id="div1"><a href="#" onclick="new Element.toggle(''div2'')">Click Me</a></DIV><br /> <DIV id="div2">Hello!</DIV></pre> <p>当点击Click Me的时?div2׃交替隐藏或显C?注意,你可以给toggle加上无限个parameter,比如Element.toggle(''div2'',''div3'',''div4'')...</p> <p>下面是每个重要的cd函数的解?</p> <p> <table height="1194" cellspacing="0" cellpadding="0" width="943" border="1"> <caption>prototype 1.2.0 的函数简?</caption> <tbody> <tr> <td width="208">函数?/td> <td width="385">解释</td> <td width="340">举例</td> </tr> <tr> <td>Element.toggle</td> <td>交替隐藏或显C?/td> <td>"Element.toggle(''div1'',''div2'')</td> </tr> <tr> <td>Element.hide</td> <td>隐藏</td> <td>"Element.hide(''div1'',''div2'')</td> </tr> <tr> <td>Element.show</td> <td>昄</td> <td>"Element.show(''div1'',''div2'')</td> </tr> <tr> <td>Element.remove</td> <td>删除</td> <td>"Element.remove(''div1'',''div2'')</td> </tr> <tr> <td>Element.getHeight</td> <td>取得高度</td> <td>"Element.getHeight(''div1'')</td> </tr> <tr> <td>Toggle.display</td> <td>和Element.toggle相同</td> <td>"Toggle.display(''div1'',''div2'')</td> </tr> <tr> <td>Insertion.Before</td> <td>在DIV前插入文?/td> <td>"Insertion.Before(''div1'',''my content'')</td> </tr> <tr> <td>Insertion.After</td> <td>在DIV后插入文?/td> <td>"Insertion.After(''div1'',''my content'')</td> </tr> <tr> <td>Insertion.Top</td> <td>在DIV里最前插入文?/td> <td>"Insertion.Top(''div1'',''this is a text'')</td> </tr> <tr> <td>Insertion.Bottom</td> <td>在DIV里最后插入文?/td> <td>"Insertion.Bottom(''div1'',''this is a text'')</td> </tr> <tr> <td>PeriodicalExecuter</td> <td>以给定频率调用一DJavaScript</td> <td>"PeridicalExecutor(test, 1)"q里test是Javascript的函?1是频?1U?.</td> </tr> <tr> <td>$</td> <td>取得一个DIV, 相当于getElementById()</td> <td>$(''div1'')</td> </tr> <tr> <td>Field.clear</td> <td>清空一个输入框</td> <td>"Field.clear(''textfield1'')</td> </tr> <tr> <td>Field.focus</td> <td>?焦点集中在输入框?/td> <td>"Field.focus(''select1'')</td> </tr> <tr> <td>Field.present</td> <td>判断内容是否为空</td> <td>"alert(Field.present(''textfield1''))"</td> </tr> <tr> <td>Field.select</td> <td>选择输入框的内容</td> <td>"Field.select(''textfield1'')"</td> </tr> <tr> <td>Field.activate</td> <td>?焦点集中在输入框上ƈ选择输入框的内容</td> <td>"Field.activate(''textfield1'')"</td> </tr> <tr> <td>Form.serialize</td> <td>把表格内容{化成string</td> <td></td> </tr> <tr> <td>Form.getElements</td> <td>取得表格内容为数lŞ?/td> <td></td> </tr> <tr> <td>Form.disable</td> <td>disable表格所有内?/td> <td>Form.disable(''form1'') (q个好象不work)</td> </tr> <tr> <td>Form.focusFirstElement</td> <td>把焦炚w中在表格W一个元素上</td> <td>Form.focusFirstElement(''form1'')</td> </tr> <tr> <td>Form.reset</td> <td>Reset表格</td> <td>Form.reset(''form1'')</td> </tr> <tr> <td>Form.Element.getValue</td> <td>取得表格输入框的?/td> <td>Form.Element.getValue(''text1'')</td> </tr> <tr> <td>Form.Element.serialize</td> <td>   把表g输入框内容{化成string</td> <td>Form.Element.serialize(''text1'')</td> </tr> <tr> <td>$F</td> <td>{同于Form.Element.getValue()</td> <td>$F(''text1'')</td> </tr> <tr> <td>Effect.Highlight</td> <td>高亮Ҏ.</td> <td>Effect.Highlight(''text1'')</td> </tr> <tr> <td>Effect.Fade</td> <td>褪色Ҏ</td> <td></td> </tr> <tr> <td>Effect.Scale</td> <td>攑֤~小(癑ֈ比)</td> <td> <p>Effect.Scale(''text1'', 200)<br /> q里200 = 200%, 即两?/p> </td> </tr> <tr> <td>Effect.Squish</td> <td>消失ҎQ文字羃后消失</td> <td>Effect.Squish(''text1'')</td> </tr> <tr> <td>Effect.Puff</td> <td>消失ҎQ文字放大后消失</td> <td>Effect.Puff(''text1'')</td> </tr> <tr> <td>Effect.Appear</td> <td>出现Ҏ</td> <td></td> </tr> <tr> <td>Effect.ContentZoom</td> <td>ZOOMҎQ?/td> <td></td> </tr> <tr> <td>Ajax.Request</td> <td>传送Ajaxhl服务器</td> <td>Ajax.Request(''http://server/s.php'')</td> </tr> <tr> <td>Ajax.Updater</td> <td>传送Ajaxhl服务器q用{复的结果更新指定的Container</td> <td>Ajax.Updater(''text1'',''http://server/s.php'')</td> </tr> </tbody> </table> </p> <p> </p> <p>Ajax的函数实际上q有一个可选参?是options.在未指明的情况下,Ajax使用的是''POST''发送请?而且是异步执?如果惌改用''GET''和同?可以用Ajax.Request(''http://server/s.php'',''get'','''',''a=1&b=2'')来执?</p> <p>在Rails中Ajax的函数被装成Ruby的函?所以不必直接采用Ajax.Request,Ajax.Updater.但是知道它是怎么工作的也很有?</p> </div> <img src ="http://www.tkk7.com/FOG/aggbug/304182.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/FOG/" target="_blank">FOG</a> 2009-11-30 00:14 <a href="http://www.tkk7.com/FOG/archive/2009/11/30/304182.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jQuery Form插g详解http://www.tkk7.com/FOG/archive/2009/11/26/303787.htmlFOGFOGThu, 26 Nov 2009 08:50:00 GMThttp://www.tkk7.com/FOG/archive/2009/11/26/303787.htmlhttp://www.tkk7.com/FOG/comments/303787.htmlhttp://www.tkk7.com/FOG/archive/2009/11/26/303787.html#Feedback3http://www.tkk7.com/FOG/comments/commentRss/303787.htmlhttp://www.tkk7.com/FOG/services/trackbacks/303787.html 

 

<script src="js/jquery.form.js" type="text/javascript"></script>

Jquery Form Plugin是jquery最重要的插件之一Q它利用AJAX技术在不引起页面刷新的情况下POST表单。主要有两个ҎQajaxform?ajaxsubmit。它会自动收集表单元素内容,军_如何理提交q程。这两个Ҏ支持多重选择。我想AJAX方式的表单应用再没有比这个插件更单易用的了?/p>

先在面里设|一个普通的表单Q?br /> Html代码 复制代码

   1. <form id=”myForm” action=”comment.php” method=”post”>  
   2.      姓名: <input type=”text” name=”name” id=”name”/>  
   3.      评论: <textarea name=”comment” id=”comment”></textarea>  
   4.      <input type=”submit” value=”提交评论” />  
   5. </form>  
   6. [/html]  

<form id=”myForm” action=”comment.php” method=”post”>
    姓名: <input type=”text” name=”name” id=”name”/>
    评论: <textarea name=”comment” id=”comment”></textarea>
    <input type=”submit” value=”提交评论” />
</form>
[/html]


加蝲jquery库和插g脚本库。然后简单地写一D初始化脚本Q这D脚本将在DOM加蝲完成时执行:
Html代码 复制代码

   1. <head>  
   2.      <script type=”text/javascript” src=”jquery.js”></script>   //加蝲jquery  
   3.      <script type=”text/javascript” src=”form.js”></script>     //加蝲插g  
   4.      <script type=”text/javascript”>  
   5.          // DOM加蝲完毕后执?nbsp; 
   6.          $(document).ready(function() {  
   7.              // l定’myForm’q定义一个简单的回调函数  
   8.              $('#myForm').ajaxForm(function() {  
   9.                  alert(”评论提交完成!”);  
  10.              });  
  11.          });  
  12.      </script>  
  13. </head>  
  14. [/html] 

<head>
    <script type=”text/javascript” src=”jquery.js”></script>  //加蝲jquery
    <script type=”text/javascript” src=”form.js”></script>    //加蝲插g
    <script type=”text/javascript”>
        // DOM加蝲完毕后执?
        $(document).ready(function() {
            // l定’myForm’q定义一个简单的回调函数
            $('#myForm').ajaxForm(function() {
                alert(”评论提交完成!”);
            });
        });
    </script>
</head>
[/html]

OKQ就是这么简单。当点击“提交评论”按钮后,表单的数据就会POST到comment.php脚本Qƈ且返?#8220;评论提交完成”信息Q如果提交成功)。页面ƈ没有hQ非常AJAX……

让我们来看看q个插gq有什么强大的功能?/p>

ajaxForm

1. 该方法须预先l定表单Q所以它一般在$(document).ready(function() { …}里定义。它能让表单在不h面的情况下POST到目标。可以ؓ该方法提供一个参敎ͼ参数一般是一个回调函数用于返回信息给用户。当然如果不提供参数也行Q只是表单提在无声无息地提交后无法得到确认了?/p>

2. 增加所有需要的事g监听器,为AJAX提交表单做好准备。ajaxForm不能提交表单。在document的ready函数中,使用ajaxForm来ؓ AJAX提交表单q行准备。ajaxForm接受0个或1个参数。这个单个的参数既可以是一个回调函敎ͼ也可以是一个Options对象?br /> 可链接(ChainableQ:可以?/p>

实例Q?br /> Js代码 复制代码

   1. $('#myFormId').ajaxForm(); 

$('#myFormId').ajaxForm();

ajaxSubmit

1. 该方法是以响应事件来通用AJAX方式提交表单。比如点L个按钮或改变了某个下拉框的|在触发事件函数里可以讄该方法。如Q?br /> Js代码 复制代码

   1. $(”#clickme”).click(function(){  
   2.    $(”#myForm”).ajaxSubmit();  
   3. }); 

$(”#clickme”).click(function(){
  $(”#myForm”).ajaxSubmit();
});

或者这P
Html代码 复制代码

   1. <select id=”mySelect” onchange=”$(‘#myForm’).ajaxSubmit();”> 

<select id=”mySelect” onchange=”$(‘#myForm’).ajaxSubmit();”>

2. 马上由AJAX来提交表单。大多数情况下,都是调用ajaxSubmit来对用户提交表单q行响应。ajaxSubmit接受0个或1个参数。这个单个的参数既可以是一个回调函敎ͼ也可以是一个Options对象?br /> 可链接(ChainableQ:可以?/p>

实例Q?br /> Js代码 复制代码

   1. // l定表单提交事g处理?nbsp; 
   2. $('#myFormId').submit(function() {  
   3.     // 提交表单  
   4.      $(this).ajaxSubmit();  
   5.     // Z防止普通浏览器q行表单提交和生页面导航(防止面hQ)q回false  
   6.     return false;  
   7.     }); 

// l定表单提交事g处理?br /> $('#myFormId').submit(function() {
    // 提交表单
    $(this).ajaxSubmit();
    // Z防止普通浏览器q行表单提交和生页面导航(防止面hQ)q回false
    return false;
   });

formSerialize

1. 该方法可以表单域的名U和D接v来,形成一个字W串Q字W串格式为name1=value1&name2=value2…比如Q?br /> Js代码 复制代码

   1. var queryString=$(”#myForm”).formSerialize(); 

var queryString=$(”#myForm”).formSerialize();

变量queryString的值将为变成name=xxx&comment=xxx。得到这个字W串后,可以?.post来提交,

如:
Js代码 复制代码

   1. $.post(”comment.php”,queryString); 

$.post(”comment.php”,queryString);

2.表单串行化Q或序列化)成一个查询字W串。这个方法将q回以下格式的字W串Qname1=value1&name2=value2?br /> 可链接(ChainableQ:不能Q?q个Ҏq回一个字W串?/p>

实例Q?br /> Js代码 复制代码

   1. var queryString = $('#myFormId').formSerialize();  
   2.  
   3. // 现在可以使用$.get?.post?.ajax{来提交数据  
   4. $.post('myscript.php', queryString); 

var queryString = $('#myFormId').formSerialize();

// 现在可以使用$.get?.post?.ajax{来提交数据
$.post('myscript.php', queryString);

fieldSerialize

1. 和formSerialize一Pq回一个字W串Q但q回的是表单指定元素或特定元素类型域的字W串。返回字W串格式也是一L。如Qvar queryString = $(’#myForm :text’).fieldSerialize();//q回myForm表单内所有文本框的字W串倹{?/p>

2.表单的字段元素串行化(或序列化Q成一个查询字W串。当只有部分表单字段需要进行串行化Q或序列化)Ӟq个方便了。这个方法将q回以下格式的字W串Qname1=value1&name2=value2?br /> 可链接(ChainableQ:不能Q这个方法返回一个字W串?/p>

实例Q?br /> Js代码 复制代码

   1. var queryString = $('#myFormId .specialFields').fieldSerialize();  

var queryString = $('#myFormId .specialFields').fieldSerialize();

fieldValue

1.q回一个数l,记录表单元素的倹{如果表单没有值则对应数组gؓI。如Q?/p>

Js代码 复制代码

   1. var data=$(’:text’).fieldValue();//q回所有表单中所有文本框cd的倹{?nbsp;

var data=$(’:text’).fieldValue();//q回所有表单中所有文本框cd的倹{?/p>

变量data为[”,”,”]q样的一个数l,数组元素对应表单元素的倹{事实上我们可以q样来得?#8220;姓名”文本框里的|var data=$(”#name”).val();Q这个元素要有ID属性)q样的作法不需要jquery form插g也可以得到倹{但使用插g可以更方便地取得单个或多个表单中特定元素域的倹{比如取得所有文本框或所有复选框的倹{只要加?#8220;:”可以。这U方法也可以用到formSerialize或fieldSerializeҎ上?br /> Js代码 复制代码

   1. var data=$(”#myForm :text”).fieldValue();//取得在myForm表单里所有文本框的倹{?nbsp;

var data=$(”#myForm :text”).fieldValue();//取得在myForm表单里所有文本框的倹{?/p>

2.q回匚w插入数组中的表单元素倹{从0.91版vQ该ҎL以数l的形式q回数据。如果元素D判定可能无效Q则数组为空Q否则它包含一个或多于一个的元素倹{?br /> 可链接(ChainableQ:不能Q该Ҏq回数组?/p>

实例Q?br /> Js代码 复制代码

   1. // 取得密码输入?nbsp; 
   2. var value = $('#myFormId :password').fieldValue();  
   3. alert('The password is: ' + value[0]);  

// 取得密码输入?br /> var value = $('#myFormId :password').fieldValue();
alert('The password is: ' + value[0]);

formToArray

同样也返回一个数l,q个数组是对象数l。对象有name和value两个属性,分别记录表单中的元素名称和元素倹{如Q?br /> Js代码 复制代码

   1. var data=$(”#myForm”).formToArray(); 

var data=$(”#myForm”).formToArray();

变量data得到的是一个对象数l。data[0].name保存myForm表单中第一个表单元素的名称属性|q里?#8221;name”。data[0].value保存myForm表单中第一个表单元素的|q里是填了什么值就是什么?br /> resetForm

1.该方法很单啦Q恢复表单初始状态。也恢复到DOM加蝲完成时的表单状态。类?#8220;重设表单”

2.清除表单元素。该Ҏ所有的文本QtextQ输入字Dc密码(passwordQ输入字D和文本区域QtextareaQ字D늽I,清除Mselect元素中的选定Q以及将所有的单选(radioQ按钮和多选(checkboxQ按钮重|ؓ非选定状态?br /> 可链接(ChainableQ:可以?br /> Js代码 复制代码

   1. $('#myFormId').clearForm(); 

$('#myFormId').clearForm();

clearFields

1.清除表单域元素。可以清除特定类型的域元素,比如清除所有文本框的,或所有复选框的域?/p>

2.清除字段元素。只有部分表单元素需要清除时才方便用?br /> 可链接(ChainableQ:可以?br /> Js代码 复制代码

   1. $('#myFormId .specialFields').clearFields();  

$('#myFormId .specialFields').clearFields();

Options对象

ajaxForm和ajaxSubmit都支持众多的选项参数Q这些选项参数可以使用一个Options对象来提供。Options只是一个JavaScript对象Q它包含了如下一些属性与值的集合Q?/p>

target

指明面中由服务器响应进行更新的元素。元素的值可能被指定Z个jQuery选择器字W串Q一个jQuery对象Q或者一个DOM元素?br /> 默认|null?/p>

url

指定提交表单数据的URL?br /> 默认|表单的action属性?/p>

type

指定提交表单数据的方法(methodQ:“GET”?#8220;POST”?br /> 默认|表单的method属性|如果没有扑ֈ默认?#8220;GET”Q?/p>

beforeSubmit

?单提交前被调用的回调函数?#8220;beforeSubmit”回调函数作ؓ一个钩子(hookQ,被提供来q行预提交逻辑或者校验表单数据。如?“beforeSubmit”回调函数q回falseQ那么表单将不被提交?#8220;beforeSubmit”回调函数带三个调用参敎ͼ数组形式的表单数据, jQuery表单对象Q以及传入ajaxForm/ajaxSubmit中的Options对象。表单数l接受以下方式的数据Q?/p>

[ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]


默认|null

success

表单成功提交后调用的回调函数。如果提?#8220;success”回调函数Q当从服务器q回响应后它被调用。然后由dataType选项值决定传回responseTextq是responseXML的倹{?br /> 默认|null

dataType

期望q回的数据类型。null?#8220;xml”?#8220;script”或?#8220;json”其中之一。dataType提供一U方法,它规定了怎样处理服务器的响应。这个被直接地反映到jQuery.httpDataҎ中去。下面的D支持Q?/p>

'xml'Q如果dataType == 'xml'Q将把服务器响应作ؓXML来对待。同Ӟ如果“success”回调Ҏ被指定, 传回responseXML倹{?/p>

'json'Q如果dataType == 'json'Q?服务器响应将被求|q传递到“success”回调ҎQ如果它被指定的话?/p>

'script'Q如果dataType == 'script'Q?服务器响应将求值成U文本?/p>


默认|nullQ服务器q回responseText|

semantic

Boolean flag indicating whether data must be submitted in strict semantic order (slower). Note that the normal form serialization is done in semantic order with the exception of input elements of type="image". You should only set the semantic option to true if your server has strict semantic requirements and your form contains an input element of type="image".
?标志,表示数据是否必须严格按照语义序QslowerQ)来进行提交。注意:一般来_表单已经按照语义序来进行了串行化(或序列化Q,除了 type="image"的input元素。如果你的服务器有严格的语义要求Q以及表单中包含有一个type="image"的input元素Q就应该?semantic讄为true。(译注Q这一D는于无法理解,译出来可能语不达意Q但误人指正。)
默认|false

resetForm

布尔标志Q表C如果表单提交成功是否进行重|?br /> Default value: null

clearForm

布尔标志Q表C如果表单提交成功是否清除表单数据?br /> 默认|null

实例Q?br /> Js代码 复制代码

   1. // 准备好Options对象  
   2. var options = {  
   3.      target:     '#divToUpdate',  
   4.      url:        'comment.php',  
   5.      success: function() {  
   6.        alert('Thanks for your comment!');  
   7.      } };  
   8.  
   9.    // options传给ajaxForm  
  10. $('#myForm').ajaxForm(options); 

// 准备好Options对象
var options = {
    target:     '#divToUpdate',
    url:        'comment.php',
    success: function() {
      alert('Thanks for your comment!');
    } };

   // options传给ajaxForm
$('#myForm').ajaxForm(options);

注意QOptions对象q可以用来将g递给jQuery?.ajaxҎ。如果你熟悉$.ajax所支持的optionsQ你可以利用它们来将Options对象传递给ajaxForm和ajaxSubmit?/p>



FOG 2009-11-26 16:50 发表评论
]]>
SQLSERVER DLL的基本操作和实例http://www.tkk7.com/FOG/archive/2009/11/24/303501.htmlFOGFOGTue, 24 Nov 2009 09:54:00 GMThttp://www.tkk7.com/FOG/archive/2009/11/24/303501.htmlhttp://www.tkk7.com/FOG/comments/303501.htmlhttp://www.tkk7.com/FOG/archive/2009/11/24/303501.html#Feedback1http://www.tkk7.com/FOG/comments/commentRss/303501.htmlhttp://www.tkk7.com/FOG/services/trackbacks/303501.html
/**
  *删除数据库中已经存在的表
 **/
if exists(select * from sys.objects where name='tb_grade')
drop table tb_grade--删除tb_grade?br /> go
if exists(select * from sys.objects where name='tb_student')
drop table tb_student--删除tb_grade?br /> go

/**
  *创徏数据?br />  **/
create table tb_student--创徏tb_student
(
   student_id int identity(1,1),--学生~号(主键,自动增长)
   student_name nvarchar(30) not null,--学生姓名(不能为空)  
   student_sex char(10) not null,--学生性别(不能为空)
   student_age int default(18),--学生q龄(默认?8)
   constraint pk_student_id primary key (student_id)
)
go
create table tb_grade--创徏tb_grade
(
  grade_id int identity(1,1),--成W~号(主键Q自动增?)
  student_id int,--外键(引用学生表student_id)
  english float,--p成W
  math float,--数学成W
  constraint pk_grade_id primary key (grade_id),--tb_student创徏主键
  constraint fk_student_id foreign key(student_id) references tb_student(student_id)--创徏外键关系
)
 
select * from tb_student
select * from  tb_grade

/**
  *创徏视图
 **/

/**
 *创徏视图的语?br />  *
 CREATE VIEW  view_name
 AS
 select_statement
*
*
*/

if exists (select * from sys.objects where name='vw_student')
drop view vw_student --删除已经存在的vw_student视图
go
create view vw_student--创徏视图vw_student
as
select * from tb_student inner join tb_grade on tb_student.student_id=tb_grade.student_id
go

/**
  *创徏索引
 **/

/**
 *创徏索引的语?br />  *
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
    ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
[ WITH < index_option > [ ,...n] ]
[ ON filegroup ]

< index_option > ::=
    { PAD_INDEX |
        FILLFACTOR = fillfactor |
        IGNORE_DUP_KEY |
        DROP_EXISTING |
    STATISTICS_NORECOMPUTE |
    SORT_IN_TEMPDB 
}
*
*
*/

if exists (select * from sys.indexes where name='index_student_id')
drop index index_student_id on tb_student --删除tb_student中的索引student_id
--创徏索引
create index index_student_id on tb_student(student_id)
go

/**
  *创徏存储q程
 **/

/**
 *
 *创徏存储q程的语?br />  *
CREATE PROC [ EDURE ] procedure_name [ ; number ]
    [ { @parameter data_type }
        [ VARYING ] [ = default ] [ OUTPUT ]
    ] [ ,...n ]

[ WITH
    { RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]

[ FOR REPLICATION ]

AS sql_statement [ ...n ]
*
*/
--不带参数的存储过E?br /> if exists (select * from  sys.objects where name='find_student')
drop procedure find_student
go
create procedure find_student
as
select * from tb_student
go
---调用存储q程
exec find_student
go
--带输入参数的存储q程
if exists (select * from  sys.objects where name='add_student_grade')
drop procedure add_student_grade
go
create procedure add_student_grade
--定义输入参数
@studentName nvarchar(30),
@studentSex char(10),
@studentAge int=18,
@gradeEnglish float,
@gradeMath float
as
    declare @studentId int
    declare @n int
    set @n=0
    begin transaction tran_add --开启事?br />     insert into tb_student(student_name,student_sex,student_age) values(@studentName,@studentSex,@studentAge)
    set @n=@@error   
 select @studentId=max(student_id) from tb_student
 set @n=@@error 
    insert into tb_grade (student_id,english,math) values(@studentId,@gradeEnglish,@gradeMath)
 set @n=@@error 
    if(@n<>0)
       begin
           rollback transaction tran_add --回滚事务
       end
    else
       begin
     commit transaction tran_add  --提交事务
       end
go
---调用存储q程
exec add_student_grade '张三','?,20,80,88
go
--带输出参数的存储q程
if exists (select * from  sys.objects where name='getCount')
drop procedure getCount
go
create procedure getCount
@n int output
as
select @n=count(*) from tb_student
go
--调用带输出参数的存储q程
declare @n int
execute getCount @n output
select @n
  
/**
 *创徏触发?br />  **/
/**
 *
 *创徏触发器的语法
 *
 *
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]
{
    { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
        [ WITH APPEND ]
        [ NOT FOR REPLICATION ]
        AS
        [ { IF UPDATE ( column )
            [ { AND | OR } UPDATE ( column ) ]
                [ ...n ]
        | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
                { comparison_operator } column_bitmask [ ...n ]
        } ]
        sql_statement [ ...n ]
    }
}
*
*
**/

IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'reminder' AND type = 'TR')
DROP TRIGGER reminder --删除触发器reminder
GO
--创徏触发器reminder(如果对表tb_studentq行d和更C息时出发)
CREATE TRIGGER reminder
ON tb_student
FOR INSERT, UPDATE
AS
RAISERROR (50009, 16, 10)
GO
---创徏DELETE触发?br /> IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'sendemail' AND type = 'TR')
DROP TRIGGER sendemail--删除触发器sendemail
GO
--创徏触发?br /> CREATE TRIGGER sendemail
ON tb_grade
FOR DELETE
AS
EXEC master..xp_sendmail' MaBin',
'Don''t forget to print a report for the distributors.'
GO



FOG 2009-11-24 17:54 发表评论
]]>
վ֩ģ壺 һӰ߿Ƭ| ѿһ| һ| ƬaëƬ| ӰԺҹײ| þ޹vwww| 鶹߹ۿ | Ƶվѿ| ޳AvƬɫҹ| ӰԺһҳСƵ߹ۿ | ݹѹۿ| 91һ߹ۿ| պƵ߹ۿ| ³˿Ƭһ| AV뾫Ʒվ߹ۿ| ޾Ʒ޿| ӰԺһҳСƵ߹ۿ | AV뾫Ʒ| ŷ޾Ʒ99ëƬѸۿ| ëƬ߹ۿ| þù޸ۿ| ޳avƬþ| ձƵһ߹ۿ| һ˿wwwѸĻ| ѧһ| þþƷ㽶| AvƷþ| ŷ߿ƬAѹۿ| ˵վ| ߾ƷAAVV| ޹պ˳| һ߹ۿ | žAV뾫ƷëƬ| Avۺɫרɫ| ŷƷպһҹҹ | Ƭ쿴| Ļ뾫ƷԴþ| ŷAVӰ߹ۿ| ƬѸƬ| ĻmvƵ7| ĻƵ|