how can I concate jstl or EL value to form a compl

2019-09-10 03:53发布

问题:

I have <a href> tag in html My model has a java list list1 as model attribute. I am trying to construct

<a href="pathvalue/namevalue">

<c:forEach var="obj" items="${list}">
  <a href="${obj.path}+"/"+${obj.name}".../>
</c:forEach>

I want to know how can I insert "/". I can directly concate two El value ${obj.path}${obj.name} but how to get that "/"

is below line correct to get a output "pathvalue/namevalue"?

<c:out value="${obj.path+'/'+obj.name}" />

回答1:

You can't concatenate it because "+" sign is used for arithmetic addition.

You should use

${obj.path}/${obj.name}

or do it in servlet to expose a bean property with already concatenated value.