﻿<?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-黑灵客栈-随笔分类-wap</title><link>http://www.blogjava.net/mstar/category/21731.html</link><description>搞软件开发就像被强奸,如果不能反抗,就享受它吧！</description><language>zh-cn</language><lastBuildDate>Mon, 21 May 2007 06:03:27 GMT</lastBuildDate><pubDate>Mon, 21 May 2007 06:03:27 GMT</pubDate><ttl>60</ttl><item><title>关于手机上传图片遇到的问题</title><link>http://www.blogjava.net/mstar/archive/2007/05/18/118371.html</link><dc:creator>黑灵</dc:creator><author>黑灵</author><pubDate>Fri, 18 May 2007 07:08:00 GMT</pubDate><guid>http://www.blogjava.net/mstar/archive/2007/05/18/118371.html</guid><wfw:comment>http://www.blogjava.net/mstar/comments/118371.html</wfw:comment><comments>http://www.blogjava.net/mstar/archive/2007/05/18/118371.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mstar/comments/commentRss/118371.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mstar/services/trackbacks/118371.html</trackback:ping><description><![CDATA[现在在做一个手机版的Blog网站，WAP1.x WAP2.0 Struts2 <br />spring hibernate<br /><ol><li>项目里面既有wml（WAP 1.x）又有xhtml（WAP 2.0）所以contenType一定要写成这个样子：<br />&lt;property name="contentType"&gt;<br />     &lt;value&gt;application/vnd.wap.xhtml+xml; charset=UTF-8&lt;/value&gt;<br /> &lt;/property&gt;<br />如果只有wml可以写成application/vnd.wap<br />ko.cn (空中网)是     text/vnd.wap.wml;charset=UTF-8<br />wap.baidu.com      wap版： text/vnd.wap.wml;charset=UTF-8<br />                            xhtml版：application/xhtml+xml<br />wap.pdx.cn(万蝶网) text/vnd.wap.wml;charset=UTF-8<br /><br /></li><li><br />不知道为什么一定要加charset=UTF-8 否则浏览器会把页面当成是一个文件，一访问就问你要不要下载，其实我们项目里还有PC版的内容 所以是在每个手机版的action中指定contentType<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">action </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="login"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="。。。。。.LoginAction"</span><span style="color: rgb(255, 0, 0);"> method</span><span style="color: rgb(0, 0, 255);">="login"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="success"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">param </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="location"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">/pages/wap/user_info.ftl</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">param</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">param </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="contentType"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />               application/vnd.wap.xhtml+xml; charset=UTF-8<br />          </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">param</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="input"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                。。。。。<br />       </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">action</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /></li><li>目前WAP 1.X还只能通过彩信业务上传图片</li><li>WAP2.0（xthml）中使用&lt;input type="file"&gt;上传文件必须指定enctype="multipart/form-data" method="post"<br />使用multipart/form-data模式时，HTTPRequest的内容不是KEY：VALUE的格式而是被用分隔符（Bandary）分成多个部分的数据流，bandary由浏览器生成，有的是一组复杂的随机数为的是与真正的数据区分开<br /></li><li>通过&lt;input type="file"&gt;上传时服务器总是报文件为空，但是文件名等信息还是在的<br />于是将手机上传的request和PC上传的request打印出来进行比较<br />做Filter拦截request<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"> InputStream is </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> request.getInputStream();</span><br /><span style="color: rgb(0, 0, 0);">FileOutputStream fs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileOutputStream(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c:/out.text</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span><br /><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] buffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];</span><br /><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> byteread </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> ((byteread </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> is.read(buffer)) </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">) {</span><br /><span style="color: rgb(0, 0, 0);">        fs.write(buffer, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, byteread);</span><br /><span style="color: rgb(0, 0, 0);">    }</span></div><br />手机版上传的request<br /></li></ol><blockquote><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="struts.token.name";</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">struts.token</span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="struts.token";</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">Q0DRQ8WNNX164DOMQQUPGQ0H4S01KS4W</span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="picture.name";</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">kmtp</span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="categoryId";</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">689</span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="photo"; filename="wps://FLASH/pht/gen/SB.jpg.jpg"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">Content-Type: image/jpeg</span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="picture.description";</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">--******_EMBIDER_MULTIPART_BOUNDARY_******--</span></div></blockquote><blockquote>PC上传的request<br /></blockquote><blockquote><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="struts.token.name"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">struts.token</span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="struts.token"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">73ZFOP68ALP9CNKDIDBK2AG9HLX86K0R</span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="picture.name"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">from pc</span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="categoryId"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">689</span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data</span><span style="color: rgb(0, 128, 0);">;</span><span style="color: rgb(0, 128, 0);"> name="photo"; filename="Skypahontas.png"</span><span style="color: rgb(0, 128, 0);"></span><br /><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">Content-Type: image/png</span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">塒NG</span><br /><span style="color: rgb(0, 0, 0);">&#x1A;</span><br /><span style="color: rgb(0, 0, 0);">  </span><br /><span style="color: rgb(0, 0, 0);">IHDR   `   `&#x8;&#x6;   鈽w8   &#x4;sBIT&#x8;&#x8;&#x8;&#x8;|&#x8;d?      pHYs  &#xB;&#x12;  &#xB;&#x12;&#x1;逸~?  %tEXtSoftware Macromedia Fireworks MX 2004噕   &#x15;tEXtCreation Time </span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">/05壣唒  -&#x1E;IDATx滍統?Wy?9缭译綮?砘-</span><span style="color: rgb(128, 0, 0); font-weight: bold;">[</span><span style="color: rgb(128, 0, 0);">迧dY?^€伉?醊H笜礞^&#x8;    &#x1;BH竃HX&#x2;!,I|    &#x1;&#x3;&#x6;&#x12;0?a駟</span><span style="color: rgb(128, 0, 0); font-weight: bold;"></span><br /><span style="color: rgb(128, 0, 0); font-weight: bold;"></span><span style="color: rgb(0, 0, 0);">偏l    賈</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">蚳泒闄^渟?Y秄$?铥&lt;</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">]]S誡烑</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">飝消?諾??</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">??馃K</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">?嘣礩鐢}爷県&#xC;≌&#x4;h&#x14;&#x2;O8攍 @揌&#x10;爥?-鼏玝悕.S.炻Z塉@&#x10;T褫6\?€</span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);">﹞?&#x5;&#x1;≌?馪?sQ榀&#x19;~t&#x1F;ru3棿溋&#x1F;籛q綷娏</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">k€Z１X颽b蟔?'??</span><br /><span style="color: rgb(0, 0, 0);">&#x15;</span><br /><span style="color: rgb(0, 0, 0);">虑司奬菦q??8?8</span><br /><span style="color: rgb(0, 0, 0);">X番残塜鐕lj喭])赱欼$?9諚&amp;;窄綫~?x!9鶹燂9c?︸&#x19;f/?锄S楆?{＄槤j鵒E纜錢諘?鱐?娠D?M?&#x6;yI=腆?｜?&#x2;?&#x2;詭S|兜某    IEND瓸`</span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x</span><br /><span style="color: rgb(0, 0, 0);">Content-Disposition: form-data; name=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">picture.description</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);"></span><br /><span style="color: rgb(0, 0, 0);">------------oLFSA1p2rcCZQCkW4ECi1x--</span></div></blockquote><blockquote>发现手机根本就没有把图片内容上传。我们测试用的手机是MOTO KRCR，而且在wap.pdx.cn wap.baidu.com上效果相同。<br />又找了一部Nokia NXX在上面安装Opera，结果不能生成bandary直接被reject掉<br />SonyEricsson可以把图片内容传上来但是编码又不对。。。。<br /><br />不知道是手机的问题 还是我们的程序有问题。<br />感觉现在手机上的浏览器还比较混乱，缺少统一的标准或者没有人来支持标准。</blockquote><img src ="http://www.blogjava.net/mstar/aggbug/118371.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mstar/" target="_blank">黑灵</a> 2007-05-18 15:08 <a href="http://www.blogjava.net/mstar/archive/2007/05/18/118371.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>