我想通过网页上的SELECT列表框,查询“最近十天内容”,“最近十十天内容”,“最近一个月内容”请问如何实现呢,
<font size="2"> 时间:</font><font size="3" color="#F59330"><select size="1" name="D10"><option value=3600 selected>
---不 限---</option>
<option value=7>七天内信息</option>
<option value=15>半月内信息</option>
<option value=30>一月内信息</option>
<option value=90>三月内信息</option>
<font size="2"> 时间:</font><font size="3" color="#F59330"><select size="1" name="D10"><option value=3600 selected>
---不 限---</option>
<option value=7>七天内信息</option>
<option value=15>半月内信息</option>
<option value=30>一月内信息</option>
<option value=90>三月内信息</option>
我们给一个环境吧(不管对不对),假设我们有些文件信息保存在服务器上,同时这些文件的一些路径与其他资料存放在数据库中,我们再假设对于文件信息的资料有两个十分重要,第一个是文件保存的路径,另一个是文件创建日期。
您可以通过点击某个执行按钮将select列表框中被选种的内容通过get or post提交给某个Servlet,并由后者通过将数据提交给数据库并从数据库中获得相应的数据,这里假设你选择了7天内的信息,我们使用select filePath as path from FileInfo where Date()-createDate <= 7,该SQL语句假设某实际数据库调用本地时间的函数为Date(),并且假定拥有一个FileInfo的文件信息表,其中filePath存放文件的实际路径,createDate保存文件创建的日期,计算出小于7天的文件并从数据库中调出他们的实际路径,最后动态生成网页(具体得有您自己完成了,我这里也只能给个泛泛的思路)。
呵呵... @.@||~
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.text.SimpleDateFormat;public class DTime {
private Date MyDate;
private SimpleDateFormat sDateFormat;
private GregorianCalendar day;
private Calendar cal;
private String time; public DTime(){
MyDate = new Date(System.currentTimeMillis());//取系统时间
sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
time = sDateFormat.format(MyDate);
day = new GregorianCalendar();
cal = Calendar.getInstance();
} public String dateNow(){//取当前时间
return time;
} public String dateMinute(int minute){//时间分钟
cal.add(Calendar.MINUTE,3);
String time = sDateFormat.format(cal.getTime());
//System.out.println(time);
return time;
} public String dateDay(int daynum){//时间加天
cal.add(Calendar.DATE,daynum);
String time = sDateFormat.format(cal.getTime());
//System.out.println(time);
return time;
} public String dateMonth(int month){//时间加月
cal.add(Calendar.MONTH,month);
String time = sDateFormat.format(cal.getTime());
//System.out.println(time);
return time;
} public String dateSecond(int second){//时间加秒
cal.add(Calendar.SECOND,second);
String time = sDateFormat.format(cal.getTime());
System.out.println(time);
return time; }}
举例:
如果你算7天前
DTime dt = new DTime();
String xday = dt.dateDay(-7);
"select filePath as path from FileInfo where Date > " + xday 是不是这样?