Path issue for uploading pictures using Jspsmartupload.jar

Source: Internet
Author: User

Program is written in Eclipse, first put the Jspsmartupload.jar package under Web-inf/lib, and then import on the JSP page;

<!--the file upload class for smartupload components--
<%@ page import= "com.jspsmart.upload.*"%>
<%@ page import= "Com.jspsmart.upload.File"%>

Upload process:

<%
Smartupload mysmartupload =new smartupload ();

Long file_size_max=4000000;

String filename2= "", ext= "", testvar= "";

Initialization

Mysmartupload.initialize (PageContext);

Allow only upload of such files

try {

Mysmartupload.setallowedfileslist ("Jpg,gif");//The file format can be modified as needed

Uploading files

Mysmartupload.upload ();

} catch (Exception e) {

%>

<script type= "Text/javascript" >

Alert ("Only allow uploading of. jpg and. gif type picture files");

window.location= ' webdesign.jsp ';

</script>

<%

}

try{

Com.jspsmart.upload.File myFile = Mysmartupload.getfiles (). GetFile (0);

if (myfile.ismissing ()) {%>

<script type= "Text/javascript" >

Alert ("Please select a file to upload first");

window.location= ' webdesign.jsp ';

</script>

<%}

else{

String Myfilename=myfile.getfilename (); Gets the file name of the uploaded files

ext= Myfile.getfileext (); Get suffix Name

int file_size=myfile.getsize (); Get the size of the file

String saveurl= "";

if (File_size<file_size_max) {

Change the file name to get the millisecond value of the current upload time

Calendar calendar = Calendar.getinstance ();

saveurl= "/upload/" + myfile.getfilename ();//Ensure that the presence of this upload directory exists in the root directory of Tomcat (that is, you need to create the appropriate folder yourself)

Myfile.saveas (saveurl);
Out.print (Saveurl);

}

}

}catch (Exception e) {


Out.print (E.tostring ());

}
%>

The red part is easy to cause the path error:

java.lang.IllegalArgumentException:This Path does not exist (1135)

The solution is to ensure that Tomcat has the presence of this upload directory in the root directory of the disk (that is, you need to create the appropriate folder yourself)

(In fact, write a function to determine whether the path exists, if it does not exist, the automatic creation of the directory should also be resolved, but not yet to try)

Path issue for uploading pictures using Jspsmartupload.jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.