Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

java - Convert integer value to string using JSTL/EL

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 ideas, aside from changing the type of id to String?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]}" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...