2010年2月15日 星期一

ajax檔案上傳使用jsp+ajax+json

一.Download json-taglib-0.4.1:
   http://www.json.org/json-zh.html
二.Download ajaxfileupload.js:
  http://www.phpletter.com/DOWNLOAD/
三.code :
     1.demoTestAction.java
        ------------------------------------------------------------------------------------------------------------------------

 
 public ActionForward doUpload(ActionMapping actionMapping,
   ActionForm  actionForm, HttpServletRequest request,
   HttpServletResponse  response) {
  String fileName= null;
  String filePatch = null;
  try{
   if  (actionForm instanceof UploadForm) {
              String encoding =  request.getCharacterEncoding();
              if ((encoding != null)  && (encoding.equalsIgnoreCase("utf-8")))
              {
                   response.setContentType("text/html; charset=utf-8");
              }

               UploadForm theForm = (UploadForm) actionForm;

               FormFile file = theForm.getTheFile();
               System.out.println("file   >>>>>>"+file);
               fileName= file.getFileName();
               System.out.println("fileName   >>>>>>"+fileName);
               
              if (file.getFileSize() > (1*1024000)) {
                return doError(response, "Upload file is too large");
               }
              
              filePatch =  createServerFile(file,request);

          }
   JSONObject  json = new JSONObject();
   json.put("isWait", filePatch);
   json.write(response.getWriter());
  }  catch (Exception e) {
   return  doError(response, e.getMessage());
  }
  return null;
 }
</pre>  
//--end
      2.demoTest.jsp
       -----------------------------------------------------------------------------------------------------------------------

         
        
  

沒有留言:

[日本][長野縣][白馬村][諏訪市] 日本白馬滑雪+你的名子場景巡禮+神社,7天6夜完整攻略

完整攻略三部曲 一部曲: 行程大綱 二部曲: 長野縣白馬村 自助 滑雪 含 交通 攻略 三部曲:你的名子/ 君の名は場景巡禮,神秘溫泉車站,諏訪湖 一部曲: 行程大綱 主要縣市: 諏訪市、松本市、長野市、東京都 主要行程: 2/24 六...