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

ÔÚjspÖÐÖ±½ÓÊä³ö¶þ½øÖÆͼƬ


<%@ page info="Random Image Show"  
    pageEncoding="UTF-8" contentType="image/jpg"  
    autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"  
%><%   
String[] imgpaths = {   
    "D:/images/testimg1.jpg",   
    "D:/images/testimg2.jpg",   
    "D:/images/testimg3.jpg"  
};   
ServletOutputStream sos = response.getOutputStream();   
FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);   
byte[] buf = new byte[100];  //»º³åÇø´óС   
int len = 0;   
while ((len = fis.read(buf)) != -1) {   
    sos.write(buf, 0, len);   
}   
sos.flush();   
sos.close();   
fis.close();   
%>  
×¢Ò⣺ÔÚÓëout»ìÓÃʱ»á³ö´í£¬Òò´ËÔÚÓÃÍêgetOutputStreamÖ®ºóҪʹ
out.clear();
out = pageContext.pushBody();
ÏÂÃæÒ»¸öÀý×Ó
Îļþ´úÂëÈçÏ£º
OutputStream o=response.getOutputStream();
//Êä³öÎļþÓõÄ×Ö½ÚÊý×飬ÿ´Î·¢ËÍ500¸ö×Ö½Úµ½Êä³öÁ÷
byte b[]=new byte[500];
//ÏÂÔصÄÎļþ
File fileLoad=new File("f:/2000","book.zip");
//¿Í»§Ê¹Óõı£´æÎļþµÄ¶Ô»°¿ò
response.setHeader("Content-disposition","attachment;filename="+"book.zip");
//֪ͨ¿Í»§ÎļþµÄMOMEÀàÐÍ
response.setContentType("application/x-tar");
//֪ͨ¿Í»§ÎļþµÄ³¤¶È
long fileLength=fileLoad.length();
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);
out.clear();
out = pageContext.pushBody();
//¶ÁÈ¡Îļþbook.zip£¬²¢·¢Ë͸ø¿Í»§ÏÂÔØ
FileInputStream in=new FileInputStream(fileLoad);
int n=0;
while((n=in.


Ïà¹ØÎĵµ£º

jspÖеÄÔªËصÄidÖµºÍnameÖµ£¬ÔÚieºÍffÖеÄÇø±ð

document.getElementById("flag")ÔÚieÖУ¬jspÖеÄÔªËØûÓÐidÖµ£¬ÓÐnameֵʱ£¬Ò²Äܲé³öÀ´£¬°´ÕÕnameÖµ²é¡£
µ«ÊÇÔÚfirefoxÖУ¬Èç¹ûûÓÐidÖµ£¬Ôò²é²»³öÀ´¡£ËùÒÔieÖУ¬nameºÍidÓÐʱͨÓ㻵«ÊÇfirefoxÖУ¬ÊÇÓÐÕâÑϸñÇø±ðµÄ¡£ ......

JSPµÄÄÚÖöÔÏó¼°·½·¨

request request±íʾHttpServletRequest¶ÔÏó¡£Ëü°üº¬ÁËÓйØä¯ÀÀÆ÷ÇëÇóµÄÐÅÏ¢£¬²¢ÇÒÌṩÁ˼¸¸öÓÃÓÚ»ñÈ¡cookie, header, ºÍsessionÊý¾ÝµÄÓÐÓõķ½·¨¡£
response response±íʾHttpServletResponse¶ÔÏ󣬲¢ÌṩÁ˼¸¸öÓÃÓÚÉèÖÃËÍ»Ø ä¯ÀÀÆ÷µÄÏìÓ¦µÄ·½·¨£¨Èçcookies,Í·ÐÅÏ¢µÈ£©
out out ¶ÔÏóÊÇjavax.jsp.JspWriterµÄÒ»¸öʵÀý£¬ ......

JSPÖÐ404´íÎóµÄ½â¾ö

 404´íÎóÊÇʲôʱºò²úÉúµÄÄØ£¿µ±ÎÒÃÇͨ¹ýä¯ÀÀÆ÷ÇëÇó·þÎñÆ÷ÉϵÄij¸ö×ÊÔ´µÄʱºò£¬¿ÉÄÜÊÇJSP£¬Ò²¿ÉÄÜÊÇServlet£¬Èç¹ûÒª·ÃÎʵÄ×ÊÔ´²»´æÔÚ£¬¾Í»á²úÉú404´íÎó£¬404´íÎó¿ÉÄÜÊÇÓ¦Óñ¾ÉíµÄÎÊÌ⣬ÀýÈçûÓÐÕý³£²¿Êð¡¢Ãû×Öд´íÁË£¬Ò²¿ÉÄÜÊÇÎļþµÄÎÊÌ⣬JSPÎļþ²»´æÔÚ¡¢Ãû×Ö´íÎ󣬻òÕßServleûÓÐÅäÖá£
¸ù¾ÝÕâЩÇé¿ö£¬404´íÎóµÄ½â¾ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ