¹ØÓÚjavaµÄhttpÐÒéÎļþÉÏ´«ÊµÓÃÀýÌâÒ»
¹ØÓÚjavaµÄhttpÐÒéÎļþÉÏ´«ÊµÓÃÀýÌâÒ»
(2006-07-25 16:43:56)
תÔØ
·ÖÀࣺ
java
¹ØÓÚjavaµÄhttpÐÒéÉÏ´«:(¼òµ¥ÊµÓöøÇÒ½¡×³;Ëٶȿì)
´Ë·½·¨±ÈapacheµÄÎļþÉÏ´«°ü(uploadfile1.1:¾ÍÎļþÉÏ´«¹¦ÄܶøÑÔ)Ҫǿ¶àÁË
1.Ö»ÐèÒªÒ»¸öMultipartRequest.java»ù±¾Îļþ¾ÍÐС£
2.ǰ̨htmlµÄ»ù±¾¸ñʽ
<html><body><form enctype="multipart/form-data"
method="post">
<input type="file" name="path"
size="38" />
<input type="text"
name="res_name" size="38" />
</body></html>
3.ºǫ́µ÷ÓôËÎļþ·½·¨ÈçÏÂ:
reqÊÇHttpServletRequestÀà.
try {
if
(req.getMethod().equals("POST") &&
MultipartRequest.isMultipart(req)) {
req = new
MultipartRequest(req, userId);//userIdµÇ½Óû§±êʶ
//µÃµ½ÉÏ´«Îļþ
File
upFile = ((MultipartRequest) req).getFile("path");
//µÃµ½ÉÏ´«ÎļþÃû
String
fileName = ((MultipartRequest) req).getFileName(upFile);
//µÃµ½ÉÏ´«httpµÄÖµ
req.getParameter("res_name");
//°ÑÉÏ´«Îļþ´æ·Åµ½c:/tempĿ¼ÏÂÃûΪ123.jpgµÄÎļþ
saveAs(upFile,
"c:/temp/123.jpg");
finally {
if (req instanceof
MultipartRequest) {
//Çå³ýÉÏ´«µÄÁÙʱÎļþ
((MultipartRequest) req).deleteTemporaryFile();
}
//°ÑÉÏ´«Îļþ´æ·Åµ½Ö¸¶¨µÄĿ¼ÏÂÎļþÃû
private void saveAs(File upFile, String filePath) throws
IOException {
FileInputStream fis =
null;
FileOutputStream fos =
null;
try {
fis = new
FileInputStream(upFile);
int len =
fis.available();
byte[] by =
new byte[len];
fis.read(by);
fos = new
FileOutputStream(filePath);
fos.write(by);
}
finally {
&n
Ïà¹ØÎĵµ£º
ת javaÉú³ÉexeÎļþ
ÎÄÕ·ÖÀà:Java±à³Ì
¶ÔÓÚ×÷Java×ÀÃæÓ¦ÓÃÀ´Ëµ£¬±È½Ï·³È˵ľÍÊÇ°²×°²¿ÊðÎÊÌ⣬¿Í»§¶ËÊÇ·ñ°²×°ÓÐjre¡¢jre°æ±¾ÎÊÌâ¡¢jreÈ¥ÄÄÏÂÔØ¡¢ÈçºÎÓÃjreÆô¶¯ÄãµÄJavaÓ¦Ó㿲»ÒªËµ¸Õ½Ó´¥µçÄÔµÄÈË£¬¾ÍËãÊDZȽÏÊìϤµçÄÔ£¬Èç¹ûûÓнӴ¥¹ýJava,Ãæ¶ÔÒ»¸öJavaÓ¦Óã¬ÈçºÎÔÚWindowsÏÂÆô¶¯Ëü£¬¹À¼Æ¶¼»áÕÛÌÚ°ëÌì¡£Èç¹û²»ÊÇÒòΪÕ⸠......
Ò»¸ö¼òµ¥µÄË«»÷¾ÍÄÜÔËÐÐjarÎļþµÄ´ò°ü¹ý³Ì:
http://blog.csdn.net/ihc523/archive/2009/10/11/4636832.aspx
eclipseµ¼³öjarÎļþÔÙ½«Ëüת»»³Éexe¿ÉÖ´ÐÐÎļþ:
http://hi.baidu.com/%C4%CF%BA%BD%CC%EC%CF%C2/blog/item/1601a381ac9af9d1bd3e1e3d.html
´òJar°üµÄÒ»¸öEclipse²å¼þFatJar:
http://blog.csdn.net/lqsmn613/ar ......
¹ØÓÚ Java Concurrency
×Ô´ÓJavaµ®Éú֮ʱ£¬Java ¾ÍÖ§³Ö²¢ÐеĸÅÄ±ÈÈçÏ̺߳ÍËø»úÖÆ¡£Õâ¸ö½Ì³Ì°ïÖú¿ª·¢¶àÏß³ÌJava³ÌÐòÔ±Äܹ»Àí½âºËÐĵÄJava²¢ÐÐÀíÄîÒÔ¼°ÈçºÎʹÓÃËûÃÇ¡£ ÄÚÈÝÉæ¼°µ½JavaÓïÑÔÖеÄỊ̈߳¬ ÖØÁ·¼¶ÒÔ¼°ÇáÁ¿¼¶Í¬²½»úÖÆ ÒÔ¼°JavaSE 5 ÖеÄËø£¬Ô×ÓÁ¿ ²¢ÐÐÈÝÆ÷£¬Ï̵߳÷¶È ÒÔ¼°Ïß³ÌÖ´ÐÐÕß ......