我想按上传的时间,对文件进行重命名.我用的是jspsmartupload组件
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
String DownloadUrl;    //存放重新命名后的文件名
String Updata;         //存放文件上传时的 年  月  日,形如 2006-6-8
Data data1=new Date();
Updata="data1.getYear+1900"+"-"+"data1.getMonth()+1"+"-"+"data1.getDate()";
DownloadUrl="data1.getYear+1900"+"data1.getMonth()+1"+"data1.getDate()"+"data1.getHours()"+"data1.getMinutes()"+"data1.getSeconds";
file.saveAs("/test/upload/"+"+DownloadUrl+");上面是我自己写的代码,越写越乱.最近要交JSP作业,以前又没怎么学JSP,基础不好...
谁帮帮我修改下代码....谢谢

解决方案 »

  1.   

    Date date1 = new Date();
    SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sf2 = new SimpleDateFormat("yyyyMMddhhmmss");
    Updata = sf1.format(date1) ;
    DownloadUrl = sf2.format(date1);
      

  2.   

    org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 9 in the jsp file: /test/admin/do_upload.jsp
    Generated servlet error:
    The type Date is ambiguous有这个错误提示...我另外新建了一个date.jsp测试了一下
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,com.jspsmart.upload.*,java.sql.*,java.text.*" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <%
    Date date1=new Date();
    out.println("date1");
    %>
    <body>
    </body>
    </html>也有同样的错误提示...这是怎么回事?
      

  3.   

    另外 要使用 SimpleDateFormat 
    是不是要加入什么包 是java.text.*么?
      

  4.   

    已经解决
    原来SQL也有DATE类...和JSP的起冲突