So I have a code listed below, I want to set ${tempUser} from session scope or ${userToEdit} from request scope if exists to new variable so I'm not gonna need to duplicate my code and gonna use ${userBean.login} etc. The problem is userBean is still the string and it throws the exception (no login property). How can I create variable of User type here?
<c:set var="userBean" scope="page">${tempUser}</c:set>
<c:if test="${not empty userToEdit}">
<c:set var="userBean">${userToEdit}</c:set>
</c:if>
<div class="section no-pad-bot" id="index-banner">
<div class="container">
<h2 class="header center orange-text">
<c:choose>
<c:when test="${not empty userToEdit}">
Edit user
</c:when>
<c:otherwise>
Add user
</c:otherwise>
</c:choose>
<c:out value="${userBean}"/>
${userBean.login}
</h2>
</div>
</div>
<c:set var="userBean" scope="page" value="${tempUser}" />
<c:if test="${not empty userToEdit}">
<c:set var="userBean" value="${userToEdit}" />
</c:if>
Or simply
<c:set var="userBean" value="${(empty userToEdit) ? tempUser : userToEdit}" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.