zoukankan      html  css  js  c++  java
  • java+jsp+mysql网页制作总结(4)

    在<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>

  • 相关阅读:
    jQuery 选择器
    http statusCode(状态码)含义
    JS实现拖拽效果
    Sql Service中的分页
    SQL Server中一些不常见的查询
    游标的基本写法
    doT.js
    关于GridView中控件的问题
    Sql Server创建函数
    ASP.NET中Ajax的用法
  • 原文地址:https://www.cnblogs.com/xxg1993/p/4524800.html
Copyright © 2011-2022 走看看