Flex+javaʵÏÖÎļþÉÏ´«
ÓÃÁËÁ½Ììʱ¼äѧϰÁËÏÂFlexºÍjavaÅäºÏʵÏÖÎļþÉÏ´«£¬ÕÒÁ˸öСÀý×Ó¡£Ç°¶Ëµ±È»ÊÇflex£¬ºǫ́ʹÓÃservlet£¬°Ñ´úÂëÌùÉÏÀ´£¬±¸Íü°É£º
FileUpload.java:
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
@SuppressWarnings("serial")
public class FileUpload extends HttpServlet
{
//¶¨ÒåÎļþÉÏ´«µÄ·¾¶
private String uploadPath = "d:\\a\\";
private int maxPostSize = 100*1024*1024;
public FileUpload()
{
super();
}
public void destroy()
{
super.destroy();
}
@SuppressWarnings("unchecked")
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
System.out.println("Access!");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print("ÒÑÁ¬½ÓÉÏ!");
//±£´æÎļþµ½·þÎñÆ÷ÖÐ
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(maxPostSize);
try
{
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while(iter.hasNext())
{
FileItem item = (FileItem)iter.next();
if(!item.isFormField())
{
String name = item.getName();
System.out.println(name);
try
{
item.write(new File(uploadPath+name));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
catch(FileUploadException e)
{
e.prin
Ïà¹ØÎĵµ£º
ÏÖÔÚ¸»webÓ¦ÓÃÒѾÊǸö´óÇ÷ÊÆ£¬Ô½À´Ô½¶àµÄ´«Í³¿Í»§¶ËÓ¦Óö¼Ïà¼Ì±»webÓ¦ÓÃËùÌæ´ú¡£µ«ÊǼøÓÚwebÓ¦ÓõÄÈõ½»»¥ÐÔ£¬ºÜ¶àÒµÎñ¸ºÔð¡¢ÈË»ú½»»¥Ç¿µÄÓ¦Óô¿js»¹ÊDz»ÄܺܺÃʤÈΣ¬Õâ¿ÖÊÇÄ¿Ç°»¹Óкܶà»îÔ¾csÓ¦ÓôæÔÚµÄÒ»¸öÖ÷ÒªÔÒò¡£Ç°²»¾Ã£¬¹«Ë¾Ò²ÔÚ×ö¼èÄѵÄÑ¡ÔñwebÓ¦ÓÃǰ̨¿ª·¢¿ò¼ÜÑ¡ÐÍÎÊÌ⣬×îº ......
4. Àí½âʼþ½×¶Î(Event Phases) ÎÒÃÇ°Ñʼþ´¥·¢Ô´·ÖΪÁ½ÀࣺһÀàÊÇÄÇЩÏÔʾÔÚ½çÃæÖеÄÔªËØÅ׳öµÄʼþ£¬Ò»ÀàÊÇÄÇЩ²»ÔÚ½çÃæÖÐÏÔʾµÄÔªËØÅ׳öµÄʼþ¡£ºÜ¼òµ¥£¬¾Ù¸öÀý×Ó£ºµÚÒ»ÀàÈçURLLoader¶ÔÏóÈ¥loadͼƬ»òÆäËû×ÊÔ´ËùÅ׳öµÄÈçcompleteʼþ£¬¾ÍÊôÓÚµÚÒ»Àà¡£½çÃæÉϵÄÒ»¸ö°´Å¥ËùÅ׳öµÄclickʼþ¾ÍÊǵڶþÀ࣬Ëü»á´¥·¢Ò»¸öʼþÁ÷£¬ ......
1.Duplicated Code ´úÂëÖظ´¼¸ºõÊÇ×î³£¼ûµÄÒìζÁË¡£ËûÒ²ÊÇRefactoringµÄÖ÷ҪĿ±êÖ®Ò»¡£´úÂëÖظ´ÍùÍùÀ´×ÔÓÚcopy-and-pasteµÄ±à³Ì·ç¸ñ¡£ÓëËûÏà¶ÔÓ¦OAOOÊÇÒ»¸öºÃϵͳµÄÖØÒª±êÖ¾¡£ 2.Long method ËüÊÇ´«Í³½á¹¹»¯µÄ“ÒŶ¾”¡£Ò»¸ö·½·¨Ó¦µ±¾ßÓÐ×ÔÎÒ¶ÀÁ¢µÄÒâͼ£¬²»Òª°Ñ¼¸¸öÒâͼ·ÅÔÚÒ»Æð¡£ 3.Large Class ´óÀà¾ÍÊÇÄã°ÑÌ«¶ ......
/ÓÉÓÚJAVAÓïÑÔµÄÊý¾ÝÀàÐͶ¼ÊÇÓзûºÅÀàÐÍ£¬¶øC# C++Ò»°ãÊý¾ÝÀàÐͶ¼ÊÇ·ÖÓзûºÅºÍÎÞ·ûºÅ,
//Òò´ËÔÚͨÐŹý³ÌÖд«µÝµÄByte[]ÎÞ·¨Ö±
½Óת»»³ÉC#ÐèÒªµÄÀàÐÍ£¬
//ÒÔÇ°µ¹ÊÇûעÒâÕâЩϸ½Ú£¬ÒòΪһ°ãÓÃÒ»ÖÖÓïÑÔ±à³Ì£¬
//´ó¶¼ÓÐÄÚÖõÄת»»·½·¨¡£¿çÓïÑÔ»·¾³µÄת»»¾ÍµÄ×Ô¼º¶¯
ÊÖÏë°ì·¨ÁË¡£
1¡¢javaµÄByte[]ת»»³Éc#µÄInt32
privat ......
¶ÔÓÚ Java 1.2£¬ÄúÖ»ÐèÓÃ
Authenticator.setDefault() °²×°Ò»¸ö Authenticator¡£ÕâÑù£¬µ±ÐèÒªÈÏ֤ʱ£¬ÒÑ°²×°µÄ Authenticator µÄ
getPasswordAuthentication() ·½·¨¾Í»á±»µ÷Óã¬È»ºóÄú¾Í¿ÉÒÔÓÃÊʵ±µÄÓû§ÃûºÍ¿ÚÁîÀ´ÉèÖà PasswordAuthentication ʵÀý¡£¾ÍÕâô¼òµ¥¡£
package
cn.arthurs.web;
import ja ......