el 表达式得到cookie的value值
作者:互联网
el 表达式得到cookie的value值
自定义一个工具类,实现需要的功能
package com.lanxin.bean; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class cookie { public static String urlDecode(String value){ try { value= URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return value; } }
创建一个对应的标签文件tld文件,放在WEB-INF下
<?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>el</short-name> <uri>http://com.lanxin.bean/cookie</uri> <function> <name>urlDecode</name> <function-class>com.lanxin.bean.cookie</function-class> <function-signature>java.lang.String urlDecode(java.lang.String)</function-signature> </function> </taglib>
在web.xml中配置该TDL的导入路径
<jsp-config> <taglib> <taglib-uri>http://com.lanxin.bean/cookie</taglib-uri> <taglib-location>/WEB-INF/cookie.tld</taglib-location> </taglib> </jsp-config>
在jsp页面引用
<%@ taglib uri="http://com.lanxin.bean/cookie" prefix="el" %> value="${el:urlDecode(cookie.user.value)}
标签:el,java,String,urlDecode,value,cookie 来源: https://blog.csdn.net/Hxp_0611/article/details/117121239