码迷,mamicode.com
首页 > 其他好文 > 详细

自定义tld标签,页面使用

时间:2016-04-08 19:33:12      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

背景需求:

系统本身的session不能在页面使用

 

如下:

controller:

@RequestMapping(method=RequestMethod.GET)
    public String getIndex(HttpServletRequest request){
        //获取工具id,返回页面工具id,为设置页面高度
        request.setAttribute("toolId",toolManager.getCurrentPlacement().getId().replaceAll("-","x"));
        //查询签到、签退状态
        Check check = checkService.getBankCheck();
        //存放签到、签退状态
        if(check!=null){
            sessionManager.getCurrentSession().setAttribute("checkType", check.getCheckType());//----------------设置此session,前台获取不到
        }else{
            sessionManager.getCurrentSession().setAttribute("checkType", 0);
        }
        return "module/check/check";
    }

技术分享

定义的tld标签和lib同级:

mysession.tld

<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"     
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"     
    version="2.0">   
    <!-- 定义函数版本 -->
    <tlib-version>1.0</tlib-version>
    <!-- 定义函数名称 -->
    <short-name>session</short-name>
    <!-- 定义第一个函数 -->
    <function>
        <!-- 定义第一个函数:reverse -->
        <name>get</name>
        <!-- 定义函数处理类 -->
        <function-class>com.yunzainfo.common.tag.MySessionTag</function-class>
        <!-- 定义函数的对应方法 -->
        <function-signature>
            java.lang.Object get(java.lang.String)
        </function-signature>
    </function>
    
    
</taglib>

 

执行标签具体的类是:

com.yunzainfo.common.tag.MySessionTag

package com.yunzainfo.common.tag;

import org.sakaiproject.tool.cover.SessionManager;


public class MySessionTag {
        
        public static Object get(String name){
            Object o = SessionManager.getCurrentSession().getAttribute(name);
            return o == null ?"":o;
        }
        

}

 

页面获取用:

//设置签到、签退状态
            if("1"=="${session:get(‘checkType‘) }"){                   //----------------------用${session:get(‘checkType‘) }获取controller中设置的值
                $("#status").html("今天您已经签到,请签退");
                $("#signIn").attr("disabled",true);
                $("#signOut").removeAttr("disabled");
            }else if("0"=="${session:get(‘checkType‘) }"){
                $("#status").html("今天您还未签到,请签到");
                $("#signOut").attr("disabled",true);
                $("#signIn").removeAttr("disabled");
            }else{
                $("#status").html("今天您已签退,不能进行操作");
                $("#signOut").attr("disabled",true);
                $("#signIn").attr("disabled",true);
            }

 

自定义tld标签,页面使用

标签:

原文地址:http://www.cnblogs.com/zrui-xyu/p/5369142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!