1. jsp a標簽如何下載 圖片後綴是jpg
定義和用法
download屬性規定被下載的超鏈接目標。
在<a>標簽中必須設置href屬性。
該屬性也可以設置一個值來規定下載文件的名稱。所允許的值沒有限制,瀏覽器將自動檢測正確的文件擴展名並添加到文件(.img,.pdf,.txt,.html,等等)。
例如:
<ahref="imges/1.jpg"download="圖片">
<imgsrc="imges/1.jpg"alt="圖片">
</a>
只有Firefox和Chrome支持download屬性。
想要兼容IE可以把下面代碼放到網頁中
<!–[ifIE]><script>
(function(l,f){functionm(){vara=e.elements;return"string"==typeofa?a.split(""):a}functioni(a){varb=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);returnb}functionp(a,b,c){b||(b=f);if(g)returnb.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);returnb.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}functiont(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","returnfunction(){varn=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[w-]+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");returnn}")(e,b.frag)}functionq(a){a||(a=f);varb=i(a);if(e.shivCSS&&!j&&!b.hasCSS){varc,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}</style>";
c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);returna}vark=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{vara=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"ina;varb;if(!(b=1==a.childNodes.length)){f.createElement("a");varc=f.createDocumentFragment();b="undefined"==typeofc.cloneNode||"undefined"==typeofc.createDocumentFragment||"undefined"==typeofc.createElement}g=b}catch(d){g=j=!0}})();vare={elements:k.elements||"etimevideo",version:"3.7.0",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)returna.createDocumentFragment();for(varb=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);returnc}};l.html5=e;q(f)})(this,document);</script><![endif]–>
2. jsp用a標簽下載文件,中文出現亂碼怎麼解決
我猜你說的中文出現亂碼應該是文件名內的中文出現亂碼。
這和伺服器,本機的編碼有關系吧。
應該在下載的過程中將伺服器文件名編碼轉換一次。
3. jsp頁面,使用 a 標簽下載 rar 文件,在IE中部彈出下載框,而是直接打開了,該如何處理,最好能給代碼
那個A標簽的鏈接寫成哪個文件的鏈接就可以了。
要寫相對路徑
4. 在JSP中使用href下載文件的問題
在JSP中,使用超級連接來下載文件的方法,可以用href屬性來指定其下載路徑及文件名,
如:
要下載路徑為:htttp://localhost:8080/HB/,文件名問140.xls的文件,
在JSP中的寫法:<a
href="htttp://localhost:8080/HB/140.xls">
140.xls</a>;
然後在瀏覽器中打開後,點擊超鏈接即可。
5. 關於在jsp中使用href超鏈接下載的問題
a標簽抄的href屬性中不能用本地硬碟的物理地址(即 f:\... 這樣的),而應該使用網路的url地址。比如說圖片和NewFile.jsp放在同一個文件夾,就可以這樣:
<a href="微信圖片_20190716111329.jpg" download="liubi.jpg">點我下載</a>