开发者

Convert integer value to string using JSTL/EL

开发者 https://www.devze.com 2023-01-13 00:25 出处:网络
How do I correct this statement: ${model.myHashtable[model.data.id]}. myHashtable is defined as Hashtable<String, String>

How do I correct this statement:

${model.myHashtable[model.data.id]}.

myHashtable is defined as

Hashtable<String, String>

But, ${model.data.id} returns an int.

I tried to do something like

${model.myHashtable['model.data.id']}

But it does not work. Any other id开发者_高级运维eas, aside from changing the type of id to String?


Set it as body of <c:set>. It will implicitly be converted to String.

<c:set var="idAsString">${model.data.id}</c:set>
<c:out value="${model.myHashtable[idAsString]}" />


${''.concat(model.data.id)} works for me,you may try it.


you can use org.apache.commons.collections4.map.CaseInsensitiveMap both String "1" and int 1 are the same key;


In JSP file:

<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

<!-- lines of code... -->

<fmt:parseNumber var = "id_value" type = "number" value = "${model.data.id}" />
<c:out value = "${id_value}" />


The $ {model.data.id} returns an integer, use Hashtable <Integer, String>, which solves my problem. If the id is a number, then <c:set> is useless.

0

精彩评论

暂无评论...
验证码 换一张
取 消