java+jsp+mysql網頁製作總結(4)

來源:互聯網
上載者:User

標籤:

在<c:forEach></c>輸出資料時怎麼顯示個數?
解決:
<c:forEach items="${list1}" var="list1" varStatus="list11">
第&nbsp;${list11.index+1 }&nbsp;次
${list1.屬性1 }
${list1.屬性2 }
。。。
</c>

 

 

計算兩個時間相差幾天的方法
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmm");
String str1="200203040000";
String timeseconds=year+month+day+"0000";
long l1=df.parse(str1).getTime(); //把字串轉化為時間
long l2=df.parse(str2).getTime();
long l3=0; //時間間隔
if(l1>l2)//判斷時間先後
{
l3=l1-l2;
}else
{
l3=l2-l1;
}
l3=l3/(60*60*24*1000);
System.out.println(str1+"與"+str2+"相隔"+l3+"天!");
}
}

 

 


錯誤:
long l1;
try{
l1=df.parse(timeseconds).getTime();}
catch{}
String timesecond=String.valueOf( l1);
顯示錯誤:The local variable l1 may not have been initialized

原因:
try{}catch{}l1不一定有值,所以會顯示錯誤
解決:
long l1;改為long l1=0;即設定初值

 

 

在jsp中如何比較sion和${list.**},並進行進一步的動作ses

解決:
可以在<script></script>比較
比如:
<c:forEach items="${list}" var="list" varStatus="list1">
<tr class="showlist">

<td id="${list1.index+1 }">
<script type="text/javascript">
s1=<%=request.getAttribute("latertime")
%>;
s2=${list.timesecond };
if(s1>s2 && s2=="00000")
{
document.write("長時間未訪問");
document.getElementById
("${list1.index+1 }").style.background=‘red‘;
}
else
{
document.write("最近訪問過");
document.getElementById
("${list1.index+1 }").style.background=‘yellow‘;
}


</script>

</td>
。。。。。。。
</c>

 

 


問題:
在一個jsp中,用${list.index}作為某個標籤的id,即<p id="${list.index+1}">
時,如果同一個jsp中有兩個list(list1,list2),在不同的<c:forEach></c>都用到
了js函數查詢id號時,會出錯
原因:
id號可能出現重名了,因為第一個<c:forEach></c>裡的id從1到list1.size(),第
二個<c:forEach></c>裡的id從1到list2.size()

解決:
在jsp裡輸入${list.index}就相當於直接輸出了,所以可以改為<p
id="${list.index+1}*">、<p id="${list.index+1}**">,以示區別,js查詢時
document.getElementById("${list1.index+1 }*").style.background=‘red‘;就可
以了

 


問題:
<textarea></textarea>沒有value屬性,怎麼輸出預設值?
解決:
<textarea 。。>${map.address}</textarea>

 

java+jsp+mysql網頁製作總結(4)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.