工作中遇到的问题及解决办法16

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小时,然后除除除就得到天数了。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值