Use of software is eclipse
<%@ page contentType="text/html; Charset=utf-8 "language=" Java "is the import=" com. Jspsmart. Upload. * % & gt; ""
<% @ page import="com. Jspsmart. Upload. *" % & gt;
<% @ page import="Java. Util. *" % & gt;
<%
String path=request. GetContextPath ();
% & gt;
<%
String newFile1Name=null;
String file_name=null;
SmartUpload mySmartUpload=new SmartUpload ();
//initialize the upload
MySmartUpload. The initialize (pageContext);
//only allowed to upload these files
Try
{
//mySmartUpload. SetAllowedFilesList (" JPG, JPG, JPG, GIF, GIF, GIF, PNG ");
MySmartUpload. Upload ();
}
The catch (Exception e)
{
//out println (" & lt; Script language=javascript> Alert (' upload format error! '); History. Back (1); </script>" );
//return;
}
Try
{
. Com. Jspsmart. Upload the File myFile.=mySmartUpload getFiles () getFile (0);
If (myFile. IsMissing ())
{
Out.println (" & lt; Script language=javascript> Alert (' must choose pictures! '); History. Back (1); </script>" );
return;
}
The else
{
Int file_size=myFile. GetSize ();//get the file size (b)
File_name=myFile. GetFileName ();
System. The out. Println (" file size: "+ +" file name: "+ file_name file_size);
//if (file_size & gt; 10 * 1024 * 1024)
//{
//out println (" & lt; Script language=javascript> Alert (' upload pictures size should be controlled between 10 k ~ 1 m! '); History. Back (1); </script>" );
//return;
//}
//else
//{
NewFile1Name=new Date (). GetTime () + file_name. Substring (file_name. IndexOf (". "));
System. The out. Println (" new file name: "+ newFile1Name);
String saveurl=request. GetSession (). GetServletContext () getRealPath (" upload ");
//String saveurl=request. GetContextPath () + "/upload";
//String saveurl="D: \ imgCache";
//System. Out. Println (saveurl);
The saveurl=saveurl + "/" + newFile1Name;
//System. Out. Println (saveurl);
MyFile. SaveAs (saveurl, mySmartUpload SAVE_PHYSICAL);
//}
}
}
The catch (Exception e)
{
E. oString ();
}
% & gt;
<script language="javascript" & gt;
Var STR=location. The toString ()
Var Result=((((STR) split ('? ')) [1]). The split () '=') [1]);
//window. Opener. _click (Result). The focus ();
Window. The parent. The document. The getElementById (Result). Value="https://bbs.csdn.net/topics/upload/";
//the window. The opener=null;
Document. The write (" upload success ");
//the window. The close ();
</script>