07年7月18日
(1)标签readonly属性在struts标签和html标签中的细微差别
在html标签中 readonly="" 即可
但是在struts中,readonly="true"或者readonly="false"才行
标签select在html和struts中的差别,进修改页面的时候,从request里面把值取出来以后
付值时的代码,html标签选中是selected,struts标签中,选中直接value="<%=effectTime%>"就行了
html:
<select name="fileTypeId">
<%
String s="";
for(int i=0;i<filetypelist.size();i++)
{
TfileType tfileType = new TfileType();
tfileType = (TfileType)filetypelist.get(i);
String tfileTypeid = tfileType.getFileTypeId().toString();
String tfileTypeName = tfileType.getFileTypeName();
if(strid.equals(tfileTypeid)){
s="selected";
}else{
s="";
}
%>
<option value="<%=tfileTypeid%>" <%=s%>><%=tfileTypeName%></option>
<%}%>
</select>
struts中
<html:select property="effectTime" value="<%=effectTime%>">
<html:option value="1">1年</html:option>
<html:option value="2">2年</html:option>
<html:option value="3">3年</html:option>
<html:option value="4">4年</html:option>
<html:option value="5">5年</html:option>
<html:option value="0">手动</html:option>
</html:select>
value="<%=effectTime%>" 是从request里取出的值,现在很少写jsp页面了,忘了很多,实在不好意思........
(2)计算时间日期差的算法
class Test2 {
public static String getDate(){
SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
Date dd = new Date();
return ft.format(dd);
}
public static long getQuot(String time1, String time2){
long quot = 0;
SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
try {
Date date1 = ft.parse( time1 );
Date date2 = ft.parse( time2 );
quot = date1.getTime() - date2.getTime();
quot = quot / 1000 / 60 / 60 / 24;
} catch (ParseException e) {
e.printStackTrace();
}
return quot;
}
public static void main(String[] args) throws Exception {
String date1 = "2008/8/8";
String date2 = getDate();
long day = getQuot(date1,date2);
System.out.println( "距离 "+date1+" 还有 "+day+" 天" );
}
}
看一下这段代码,是从今天到2008/8/8的天数。
Date的getTime()方法返回自1970年1月1日午夜(通用时间)以来的毫秒数。
用2008/8/8的getTime()减去今天的getTime()就是这两天相差的毫秒数,1秒=1000毫秒,1分钟=60秒,1小时=60分钟,1天=24小时,然后除除除就得到天数了。