JSP deletes files on the server

Source: Internet
Author: User
Tags tomcat apache tomcat
js| Server

A little problem

JSP deletes files on the server

It's been debugged for a long time.

The results show that the problem of test absolute path

It's done now. '

<%@ page contenttype= "text/html; charset=gb2312 "language=" java "import=" java.sql.* "errorpage=" "%>"
<%@ page import= "java.io.*"%>
<%
String Path = Application.getrealpath ("/"); Get the current absolute path
String url= path+ "at.jpg"; Get absolute file name
Out.println (URL);
Out.println ("<br>File f=new file (URL);
Boolean flag=false;
if (f.exists ()) ... {//If file exists Delete if file does not exist print out file not found
Flag=f.delete ();
if (flag)
... {
OUT.PRINTLN ("Success");
}
Else
... {
Out.println ("file can not delete");
}
}
Else
OUT.PRINTLN ("File not exists");

%>

Environment Red Hat Enterprise Linux as Release 3 (Taroon)
Kernel 2.4.21-4.el on a i686
Tomcat:apache tomcat/5.5.20







Related Article

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.