Java-JSTL及EL表达式学习笔记

jstl中的if与forEach

<c:if test="${VvvvDown_flag ne null }">
    <div style="background:#D2ECED;font-size:16;width:60%;">其它歌曲</div>
    <div>
        <p>
        <table>
            <c:if test="${nonEasouEntity ne null}">
                <tr><td>歌曲名:</td><td><b>${nonEasouEntity.song}</b></td></tr>
                <tr><td>歌手名:</td><td><b>${nonEasouEntity.songer}</b></td></tr>
                <tr><td colspan="2">下载链接:</td></tr>
                <c:forEach var="items" items="${itemsList}" varStatus="vs">
                    <tr><td colspan="2"><a href="${items.downurl}">${items.filetype}</a></td></tr>
                </c:forEach>
            </c:if>
            <c:if test="${nonEasouEntity eq null}"><tr><td colspan="2">暂无资源</td></tr></c:if>
        </table>
        </p>
    </div>
</c:if>

比较

<TD class=gridViewItem>
    <c:if test="${fn:contains(music.picUrl,'upload')}">
        <img alt="本地图片" src="${ctx }/${music.picUrl} " height="40:px" width="40:px">
    </c:if>
    <c:if test="${fn:contains(music.picUrl,'http')}">
        <img alt="本地图片" src="${music.picUrl} " height="40:px" width="40:px">
    </c:if>
    <c:if test="${music.picUrl eq ''||music.picUrl==null}">
        <img alt="本地图片" src="${ctx }/manage/img/manage_pic.png" height="40:px" width="40:px">
    </c:if>
</TD>
<TD class=gridViewItem>
    ${music.musicOrder }
    <c:if test="${music.musicStatus!=0}">
        <a href="${ctx }/manage/music/changeOrder.do?musicId=${music.id }&type=up&channelId=${channel.id}">
            <img src="${ctx }/manage/img/icon_up.gif"></img></a>
        <a href="${ctx }/manage/music/changeOrder.do?musicId=${music.id }&type=down&channelId=${channel.id}"><img src="${ctx }/manage/img/icon_down.gif"></img> </a>
    </c:if>
</TD>
<td class=gridViewItem>
    <c:if test="${music.nonEasouSongId == '0'}">
        <font color="red">宜搜</font>
    </c:if>
    <c:if test="${music.nonEasouSongId != '0'}">
        非宜搜&nbsp;Id:<font color="green"><b>${music.nonEasouSongId}</b></font>
    </c:if>
</td>

selected提交表单
js

/*提交查询表单*/
function nonEasouIdSubmit()
{
    document.getElementById("searchForm").submit();
}

jsp

<select name="nonEasouId" id="nonEasouId" onchange="nonEasouIdSubmit()">
    <option value="" <c:if test="${nonEasouId==null}">selected</c:if>>
    请选择
    </option>
    <option value="0" <c:if test="${nonEasouId==0}">selected</c:if>>
    宜搜
    </option>
    <option value="-1" <c:if test="${nonEasouId!=0 && nonEasouId!=null}">selected</c:if>>
    非宜搜
    </option>
</select>

jstl定义变量

whichdown的结构

public class WhichDown implements Serializable {
    /**
     * @Fields serialVersionUID
     */
    private String music;    //歌曲名
    private String author;    //歌手名
    private String source;    //来源
    private Map<String, List<Items>> map = new HashMap<String, List<Items>> ();
    private String totalType ;// 版本总类型表示 0:压缩 ; 1:普通;2:清晰 ;3:保真
    private String whichId;    //来源id
    …………
    public class Items implements Serializable{
        private String filedtype;
        private String filedid;
        private String downurl;
        private String filedtype2;
        private String size ;//版本歌曲大小
    …………

jsp

<c:set var="whichDown" value=""/>
<c:choose>
    <c:when test="${vvvvDown ne null }">
        <c:set var="whichDown" value="${vvvvDown }"/>
    </c:when>
    <c:otherwise>
        <c:set var="whichDown" value="${easouDown }"/>
    </c:otherwise>
</c:choose>
<c:choose><c:when test="${whichDown.map['common'] ne null}"><c:set var="music" value="${whichDown.map['common']}"/></c:when>
    <c:otherwise><c:set var="music" value="${whichDown.map['gaochao']}"/></c:otherwise></c:choose>
<nav>
    <script src='${ctx }/head/js/imgReady.js'></script>
    <aside>
        <b id="speedImg"></b>
    </aside>
    <h1>
        <figure class="fig_marquee">${whichDown.song}<c:if test="${whichDown.songer ne null && whichDown.songer ne ''}">-${whichDown.songer}</c:if></figure>
        <script>
            var $=function(par){
                return "string"==typeof par?document.getElementById(par):par;
            };
        </script>
    </h1>
</nav>

js返回 超链接的点击响应

<div style="float: right"><a href="javascript:history.go(-1)">返回</a></div>
<a href="javascript:location.href=encodeURI('${ctx }/manage/verifyPhone/clearAll.do?brandName=&phoneOs=${phoneOs }&phoneStatus=${phoneStatus }')">清空</a>

设置表单控件的宽度

品牌名:<input type="text" id="brandName" style="max-width:100px" name="brandName" />

任务计划测试示例

<style type="text/css">
    .STYLE2 {font-size: 13px}
    .STYLE3 {font-size: 13px; line-height:2px}
</style>
<body>
<script type="text/javascript" charset="utf-8">
    jQuery(function($){
        $('#startDate1').datepicker({
            yearRange: '1900:2099', //取值范围.
            showOn: 'both', //输入框和图片按钮都可以使用日历控件。
            buttonImage: '../js/date/calendar.gif', //日历控件的按钮
            buttonImageOnly: true,
            showButtonPanel: true
        });
        $('#startDate2').datepicker({
            yearRange: '1900:2099', //取值范围.
            showOn: 'both', //输入框和图片按钮都可以使用日历控件。
            buttonImage: '../js/date/calendar.gif', //日历控件的按钮
            buttonImageOnly: true,
            showButtonPanel: true
        });
    });
</script>
<script type="text/javascript">
    //整个Step3的对象
    function SubStep3(startDate,startHour,startMin,intervalDay,intervalWeek,whichDay,whichWeek,whichWeekDay,whichMonth,week,month){
        this.startDate=startDate;
        this.startHour=startHour;
        this.startMin=startMin;
        this.intervalDay=intervalDay;
        this.intervalWeek=intervalWeek;
        this.whichDay=whichDay;
        this.whichWeek=whichWeek;
        this.whichWeekDay=whichWeekDay;
        this.whichMonth=whichMonth;
        this.week=[false,false,false,false,false,false,false];
        this.month=[false,false,false,false,false,false,false,false,false,false,false,false];
    }
    //var Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday;
    //var January,February,March,April,May,June,July,August,September,October,November,December;
    //var startDate,startHour,startMin,intervalDay,intervalWeek,whichDay,whichWeek,whichMonth;
    var SubStep3=new SubStep3();
    var step_3=new Array();
    var step_3_1=new Object();
    var step_3_2=new Object();
    var step_3_3=new Object();
    var step_3_4=new Object();
    function divStep_3_1Click(){
    }
    function divStep_3_2Click(){
    }
    function divStep_3_3Click(){
    }
    function divStep_3_4Click(){
    }
    //检查是否为数字
    function checkNum(){
        var eventcode=event.keyCode;
        if(!(eventcode>=48 && eventcode<=57)){
            event.returnValue=false;
        }
    }
    //检查日期
    function checkStartDate(divId,fieldId){
        var splitDate=document.getElementById(fieldId).value.split("-");
        var year=Number(splitDate[0]);
        var month=Number(splitDate[1]);
        var day=Number(splitDate[2]);
        Date date=new Date();
        if(year<1970 || year>3000 || month>12 || month<0 || day>31 ||day<0){
            document.getElementById(fieldId).value="";
        }
        else{
            date.setDate(year).setMonth(month).setFullYear(day);
//alert(date.toString());
        }
        setDivValue(divId,fieldId);
    }
    //检查小时
    function checkStartHour(divId,fieldId){
        if((+document.getElementById(fieldId).value)>24){
            document.getElementById(fieldId).value="";
        }
        setDivValue(divId,fieldId);
    }
    //检查分钟
    function checkStartMin(divId,fieldId){
        if((+document.getElementById(fieldId).value)>59){
//alert("_______:"+document.getElementById(fieldId).value);
            document.getElementById(fieldId).value="";
        }
        setDivValue(divId,fieldId);
    }
    //-------------------------------------
    //检查间隔天数
    function checkIntervalDay(divId,fieldId){
        if((+document.getElementById(fieldId).value)>366){
            document.getElementById(fieldId).value="";
        }
        setDivValue(divId,fieldId);
    }
    //检查间隔周数
    function checkIntervalWeek(divId,fieldId){
        if((+document.getElementById(fieldId).value)>52){
            document.getElementById(fieldId).value="1";
        }
        setDivValue(divId,fieldId);
    }
    //把值设置到对应的div对象属性中
    function setDivValue(divId,fieldId){
        var fieldValue=document.getElementById(fieldId).value;
        if(divId=="step-3-1"){
            alert("setDivValue___fieldValue:"+fieldValue);
            setField(fieldId,fieldValue);
        }
        else if(divId=="step-3-2"){
            setField(fieldId,fieldValue);
        }
        else if(divId=="step-3-3"){
            setField(fieldId,fieldValue);
        }
        else if(divId=="step-3-4"){
            setField(fieldId,fieldValue);
        }
    }
    //设置对象属性的值
    function setField(fieldId,fieldValue){
        var fieldIdArr=["startDate","startHour","startMin","intervalDay","intervalWeek","whichDay","whichWeek","whichWeekDay","whichMonth"];
        alert("setField___fieldValue:"+fieldValue);
        alert("fieldId:"+fieldId);
        alert(fieldId.toString() == fieldIdArr[0].toString());
        if(fieldId == fieldIdArr[0]){
            step_3_1.startDate=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.startDate);
        }
        else if(fieldId == fieldIdArr[1]){
            step_3_1.startHour=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.startHour);
        }
        else if(fieldId == fieldIdArr[2]){
            step_3_1.startMin=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.startMin);
        }
        else if(fieldId == fieldIdArr[3]){
            step_3_1.intervalDay=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.intervalDay);
        }
        else if(fieldId == fieldIdArr[4]){
            step_3_1.intervalWeek=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.intervalWeek);
        }
        else if(fieldId == fieldIdArr[5]){
            step_3_1.whichDay=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.whichDay);
        }
        else if(fieldId == fieldIdArr[6]){
            step_3_1.whichWeek=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.whichWeek);
        }
        else if(fieldId == fieldIdArr[7]){
            step_3_1.whichWeekDay=fieldValue;
            alert("setField___step_3_1.whichWeekDay:"+step_3_1.whichWeekDay);
        }
        else if(fieldId == fieldIdArr[8]){
            step_3_1.whichMonth=fieldValue;
            alert("setField___step_3_1.intervalDay:"+step_3_1.whichMonth);
        }
    }
    //检查第几天
    function checkWhichDay(divId,fieldId){
        if((+document.getElementById(fieldId).value)>31){
            document.getElementById(fieldId).value="1";
        }
        setDivValue(divId,fieldId);
    }
    //选择天被点击
    function selWhichDayClick(divId,enableFieldId,disableFieldId1,disableFieldId12){
        document.getElementById(enableFieldId).disabled=false;
        document.getElementById(disableFieldId1).disabled=true;
        document.getElementById(disableFieldId12).disabled=true;
        setDivValue(divId,enableFieldId);
    }
    //选择周被点击
    function selWhichWeekClick(divId,enableFieldId1,enableFieldId2,disableFieldId){
        document.getElementById(disableFieldId).disabled=true;
        document.getElementById(enableFieldId1).disabled=false;
        document.getElementById(enableFieldId2).disabled=false;
        setDivValue(divId,enableFieldId1);
        setDivValue(divId,enableFieldId2);
    }
    //当每周的星期被点击
    function weekCheckbox(divId,fieldName,fieldId){
    }
    //当每月的星期被点击
    function monthClick(divId,fieldName,fieldId){
    }
</script>
<!-- 每天-->
<div id="step-3-1" onclick="divStep_3_1Click()">
    <table class="STYLE3">
        <tr><td>请选择任务运行的起始时间与日期</td></tr>
        <tr class="STYLE3"><td>&nbsp;</td></tr>
        <tr>
            <td>起始时间:</td>
        </tr>
        <tr>
            <td>
                <input id="dayStartHour" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartHour('step-3-1','dayStartHour')"/>时:
                <input id="dayStartMin" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartMin('step-3-1','dayStartMin')"/></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td>运行这个任务:</td>
        </tr>
        <tr>
            <td><input id="intervalDay" type="test" size="4" maxlength="3" value="1" onkeypress="checkNum()" onblur="checkIntervalDay('step-3-1','intervalDay')"/></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td>起始日期:</td>
        </tr>
        <tr>
            <td><input id="startDate1" type="text" name="startDate" id="startDate" value=""></td>
        </tr>
    </table>
</div>
<!-- 每周-->
<div id="step-3-2" onclick="divStep_3_2Click()">
    <table class="STYLE3">
        <tr><td colspan="2">请选择任务运行的起始时间与日期</td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td colspan="2">起始时间:</td>
        </tr>
        <tr>
            <td colspan="2">
                <input id="weekStartHour" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartHour('step-3-2','weekStartHour')"/>时:
                <input id="weekStartMin" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartMin('step-3-2','weekStartMin')"/></td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
        <tr>
            <td colspan="2">运行这个任务:</td>
        </tr>
        <tr>
            <td colspan="2"><input id="intervalWeek" type="test" size="4" maxlength="3" value="1" onkeypress="checkNum()" onblur="checkIntervalWeek('step-3-2','intervalWeek')"/></td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
        <tr>
            <td colspan="2">请选择下面日期:</td>
        </tr>
        <tr>
            <td><label><input id="Monday" name="week" type="checkbox" value="Monday" checked="checked" onclick="weekCheckbox('step-3-2','week','Monday')"/>星期一</label></td>
            <td><label><input id="Tuesday" name="week" type="checkbox" value="Tuesday" onclick="weekCheckbox('step-3-2','week','Tuesday')"/>星期二</label></td>
        </tr>
        <tr>
            <td><label><input id="Wednesday" name="week" type="checkbox" value="Wednesday" onclick="weekCheckbox('step-3-2','week','Wednesday')"/>星期三</label></td>
            <td><label><input id="Thursday" name="week" type="checkbox" value="Thursday" onclick="weekCheckbox('step-3-2','week','Thursday')"/>星期四</label></td>
        </tr>
        <tr>
            <td><label><input id="Friday" name="week" type="checkbox" value="Friday" onclick="weekCheckbox('step-3-2','week','Friday')"/>星期五</label></td>
            <td><label><input id="Saturday" name="week" type="checkbox" value="Saturday" onclick="weekCheckbox('step-3-2','week','Saturday')"/>星期六</label></td>
        </tr>
        <tr>
            <td><label><input id="Sunday" name="week" type="checkbox" value="Sunday" onclick="weekCheckbox('step-3-2','week','Sunday')"/>星期日</label></td>
        <tr><td colspan="2">&nbsp;</td></tr>
        </tr>
    </table>
</div>
<!-- 每月-->
<div id="step-3-3" onclick="divStep_3_3Click()">
    <table class="STYLE3">
        <tr><td colspan="2">请选择任务运行的起始时间与日期</td></tr>
        <tr><td colspan="2">&nbsp;</td></tr>
        <tr colspan="2">
            <td>起始时间:</td>
        </tr>
        <tr colspan="2">
            <td>
                <input id="monthStartHour" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartHour('step-3-3','monthStartHour')"/>时:
                <input id="monthStartMin" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartMin('step-3-3','monthStartMin')"/></td>
        </tr>
        <tr>
            <td colspan="2">每月:</td>
        </tr>
        <tr>
            <td colspan="2">
                <label>
                    <input type="radio" id="selWhichDay" name ="everyMonth" value="" onclick="selWhichDayClick('step-3-3','whichDay','whichWeek','whichWeekDay')"/>&nbsp;
                    <input id="whichDay" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkWhichDay()"/><br />
                </label>
            </td>
        </tr>
        <tr>
            <td>
                <input type="radio" id="selWhichWeek" name ="everyMonth" value="" onclick="selWhichWeekClick('step-3-3','whichWeek','whichWeekDay','whichDay')"/>
                <select id="whichWeek" name="whichWeek">
                    <option value="firstWeek" selected="selected">第一个</option>
                    <option value="secondWeek">第二个</option>
                    <option value="thirdWeek">第三个</option>
                    <option value="fourthWeek">第四个</option>
                    <option value="lastWeek">最后一个</option>
                </select>星期&nbsp;
            </td>
            <td>
                <select id="whichWeekDay" name="whichWeekDay">
                    <option value="Monday" selected="selected">星期一</option>
                    <option value="Tuesday">星期二</option>
                    <option value="Wednesday">星期三</option>
                    <option value="Thursday">星期四</option>
                    <option value="Friday">星期五</option>
                    <option value="Saturday">星期六</option>
                    <option value="Sunday">星期日</option>
                </select>
            </td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
        <tr>
            <td>月份:</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><label><input type="checkbox" name="month" id="January" value="January" checked="checked" onclick="monthClick('step-3-3','month','January')"/>一月</label>&nbsp;
                <label><input type="checkbox" name="month" id="February" value="February" onclick="monthClick('step-3-3','month','February')"/>二月</label></td>
            <td><label><input type="checkbox" name="month" id="March" value="March" onclick="monthClick('step-3-3','month','March')" />三月</label>&nbsp;&nbsp;
                <label><input type="checkbox" name="month" id="April" value="April" onclick="monthClick('step-3-3','month','April')" />四月</label></td>
        </tr>
        <tr>
            <td><label><input type="checkbox" name="month" id="May" value="May" onclick="monthClick('step-3-3','month','May')" />五月</label>&nbsp;
                <label><input type="checkbox" name="month" id="June" value="June" onclick="monthClick('step-3-3','month','June')" />六月</label></td>
            <td><label><input type="checkbox" name="month" id="July" value="July" onclick="monthClick('step-3-3','month','July')" />七月</label>&nbsp;&nbsp;
                <label><input type="checkbox" name="month" id="August" value="August" onclick="monthClick('step-3-3','month','August')" />八月</label></td>
        </tr>
        <tr>
            <td><label><input type="checkbox" name="month" id="September" value="September" onclick="monthClick('step-3-3','month','September')" />九月</label>&nbsp;
                <label><input type="checkbox" name="month" id="October" value="October" onclick="monthClick('step-3-3','month','October')" />十月</label></td>
            <td><label><input type="checkbox" name="month" id="November" value="November" onclick="monthClick('step-3-3','month','November')" />十一月</label>
                <label><input type="checkbox" name="month" id="December" value="December" onclick="monthClick('step-3-3','month','December')" />十二月</label></td>
        </tr>
    </table>
</div>
<!--每次-->
<div id="step-3-4" onclick="divStep_3_4Click()">
    <table class="STYLE3">
        <tr><td>请选择任务运行的起始时间与日期</td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td>起始时间:</td>
        </tr>
        <tr>
            <td>
                <input id="onceStartHour" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartHour('step-3-4','onceStartHour')"/>时:
                <input id="onceStartMin" type="text" size="3" maxlength="2" vlaue="0" onkeypress="checkNum()" onblur="checkStartMin('step-3-4','onceStartMin')"/></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td>起始日期:</td>
        </tr>
        <tr>
            <td><input id="startDate2" type="text" name="startDate" id="startDate" value=""></td>
        </tr>
    </table>
</div>
</body>

版权所有,转载请注明出处 luowei.github.io.