Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÔÚJSPÖÐÏÂÔØÎı¾Îĵµ

ͨ³££¬ÎÒÃÇÐèÒªÌṩһ¸öÎļþÏÂÔصÄʱºò£¬½öÐèÒªÒ»¸ö³¬Á´½Ó¾Í¿ÉÒÔ½â¾ö¡£
 
±ÈÈçexeÎļþ£¬Êó±ê×ó¼üµã»÷Á´½Ó¾Í»áÌáʾÄãÖ±½ÓÖ´Ðл¹ÊDZ£´æ£¬ÓÒ¼üÔò¿ÉÒÔÖ±½ÓÁí´æΪ¡£¡£¡£
 
µ«ÊÇÓÐÒ»²¿·ÖÎļþ£¬±ÈÈçtxtµÈ¿ÉÒÔÔÚä¯ÀÀÆ÷ÖÐÖ±½Ó´ò¿ªµÄÎļþ£¬ÄãÖ»ÄÜÓÃÊó±êÓÒ¼üµã»÷Á´½ÓÈ»ºóÁí´æΪµÄ·½Ê½È¥±£´æ¸ÃÎļþ£¬Èç¹ûÖ±½Óµã»÷×ó¼ü£¬¸ÃÎļþ¾ÍÔÚä¯ÀÀÆ÷Öб»´ò¿ªÁË¡£
 
ÔÚһЩÐèÇóÖУ¬ÎÒÃÇÐèÒªÈÃtxtÓµÓÐexeÎļþÀàËƵĶ¯×÷£¬¼´×ó¼üµã»÷ʱҲÈÃËüÌáʾ±£´æ»¹ÊÇ´ò¿ª¡£
 
ÍøÉϺܶàÎÄÕ¶¼Ìáµ½ÓÃjspsmartuploadÈ¥×öÕâ¼þÊÂÇ飬smartuploadµ±È»ÊǸöºÃ¶«Î÷£¬¿ÉÒÔÓõÄʱºò¾¡¹ÜÓ㬵«ÊÇËü²¢²»ÊDZØÐëµÄ£¬ÎÒÃÇÔÚjspÖпÉÒÔÖ±½ÓÉèÖÃresponseµÄHeader (Content-Disposition) À´´ïµ½Ä¿µÄ¡£ÏÂÃæÊÇÕû¸ö¹ý³Ì£º
 
1£©Ê×ÏÈÄãÒªÌṩһ¸öÏÂÔصÄÁ´½Ó£¬»òÕßbutton£¬È磺
<a href="download.jsp">ÎļþÏÂÔØ</a>
<button type="submit" onClick="window.open('download.jsp')">ÎļþÏÂÔØ</button>
×ÜÖ®£¬ÐèÒªÓÐÒ»¸ö·½·¨Ìøתµ½ÊµÏÖÎļþÏÂÔصÄjsp»òÕßservletÖС£
 
2£©ÔÚdownload.jsp£¨»òÕßʵÏÖͬÑù¹¦ÄܵÄservlet£©ÖУ¬´úÂëÈçÏ£º
<%@ page contentType="text/html;charset=gb2312"%>
<%   
     /* Ç°°ë²¿·ÖÊÇ»ñµÃserverÉÏwebcontentµÄÕæʵ·¾¶£¬
      * ÒòΪ»ñµÃÒ»¸öFileInputStream±ØÐëʹÓÃ"E:/webcontent/filename.txt"ÕâÖÖÀàÐ͵ÄÕæʵ·¾¶£¬
      * ¶ø²»ÊÇ"http://www.xxx.com/xxx/filename.txt"ÕâÖÖURLµÄÐÎʽ¡£
      * dataname ÊǾßÌåµÄÎļþÏà¶ÔÓÚwebcontentµÄ·¾¶ */
     String fullname = request.getSession().getServletContext().getRealPath("/") + dataname;
 
     // filenameÊDZ£´æʱµÄĬÈÏÎļþÃû£¬¾­ÊµÑ飬ÔÚFirefox2ºÍIE7ÖУ¬Õâ¸öÎļþÃûÊÇÓÐÓõģ¬ÔÚIE6ÖÐËƺõûʲôÓã¬ÓÐÐËȤµÄÈËÔÙÈ¥Ñо¿Ñо¿°É
     String filename = fullname.substring(fullname.lastIndexOf('/'));   
     int i = 0;  
     response.setContentType("text/plain"); 
 
     // ¹Ø¼üÊÇÉèÖÃÕâ¸öHea


Ïà¹ØÎĵµ£º

jspÖÐͨ¹ýURLµØÖ·»ñÈ¡¸ÃµØÖ·Ò³ÃæÖеľ²Ì¬Ò³Ãæ


try {
            URL url = new URL("http://www.163.com");
            InputStream is = url.openStream();
            byte[] buffer = new byte[1024];
           ......

js¡¢jsp´«µÝ²ÎÊýÂÒÂëÎÊÌâ½â¾ö

ÒÔÇ°ÓÐÌáµ½¹ýÂÒÂëÎÊÌ⣬×î½üÔÚʹÓÃwindow.openʱÓÖ³öÏÖ´ËÀàÎÊÌ⣬ÏÖ½â¾öÈçÏ£º
1£ºÊ¹ÓÃencodeURIComponentº¯Êý¶Ô²ÎÊý½øÐд¦Àí£¬ÀýÈ磺window.open("html.jsp?name=" + encodeUrlComponent(value)));
2£ºÐÞ¸Ätomcat·þÎñÆ÷µÄserver.xmlÎļþÌí¼Ó£ºuseBodyEncodingForURI="true"»òÕß
URIEncoding=" ......

jsp¿Í»§¶ËÈ¥»º´æºÍ·þÎñ¶ËÈ¥»º´æ

 
ÍøÒ³»º´æµÄ×÷ÓÃÊÇʲô£¿Ó¦¸ÃºÜÖØÒª¡£µ«ÊÇÎÒÃÇÔÚ¿ª·¢ÍøÂçÓ¦ÓõÄʱºò£¬ÍøÒ³»º´æ×ÜÊǸøÎÒÃÇÒ»ÖÖĪÃûµÄ·³ÄÕ¡£ÓÚÊǼ¸ºõÿһ¸ö¿ª·¢Õ߶¼ÊÔͼ½â¾ö¹ýÕâ¸öÎÊÌâ¡£µ±È»£¬ÎÒÒ²²»ÊǽñÌì²Å×ÅÊÖ½â¾öÕâ¸öÎÊÌâ¡£µ«ÊǽñÌìһʱÐÄѪÀ´³±£¬Ð´Ò»Æª£¬¼Ç¼һÏÂÓõ½µÄ·½·¨¡£
1.½ûÖ¹¿Í»§¶Ë»º´æÒªÔÚ<head>ÖмÓÈëÀàËÆÈçÏÂÄÚÈÝ(ÎÒµ±È»»¹Ã»Ó ......

jspÓÐÄÄЩÄÚÖöÔÏó?×÷Ó÷ֱðÊÇʲô?

JSP¹²ÓÐÒÔÏÂ9ÖÖ»ù±¾ÄÚÖÃ×é¼þ£¨¿ÉÓëASPµÄ6ÖÖÄÚ²¿×é¼þÏà¶ÔÓ¦£©£º
¡¡1.request Óû§¶ËÇëÇ󣬴ËÇëÇó»á°üº¬À´×ÔGET/POSTÇëÇóµÄ²ÎÊý¡£
   2. response ÍøÒ³´«»ØÓû§¶ËµÄ»ØÓ¦ ¡£
   3.pageContext ÍøÒ³µÄÊôÐÔÊÇÔÚÕâÀï¹ÜÀí ¡£
   4.session ÓëÇëÇóÓйصĻỰÆÚ¡£
   5.ap ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ