![](/img/trans.png)
[英]java.lang.illegalargumentexception cannot set java.lang.string field to java.lang.String
[英]Cannot set JSTL User variable instead of java.lang.String
因此,我在下面列出了一個代碼,我想從會話范圍設置$ {tempUser}或從請求范圍設置$ {userToEdit}(如果存在)到新變量,因此我不需要復制代碼並使用$ {userBean。登錄}等。問題是userBean仍然是字符串,它會引發異常(無登錄屬性)。 如何在此處創建用戶類型的變量?
<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>
或者簡單地
<c:set var="userBean" value="${(empty userToEdit) ? tempUser : userToEdit}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.