基于条件的单选按钮自动检查使用jstl

Kal*_*ran 3 jstl

我需要根据请求中的值将单选按钮设置为已选中.下面是我在JSP中使用的代码

<input type="radio" name="status" id="status" value="Active" checked="<c:if test="${posting.postingStatus eq 'Active'}">checked</c:if>">
                Active&nbsp; 
<input type="radio" name="status" id="status" value="Closed" checked="<c:if test="${posting.postingStatus eq 'Closed'}">checked</c:if>">
                Closed
Run Code Online (Sandbox Code Playgroud)

我正在获取radiobutton以及文本'checked /> Active'和另一个带文本'checked /> Closed'的单选按钮

我尝试使用另一组代码

<c:choose>
    <c:when test="${posting.postingStatus eq 'Active'}">
    <input type="radio" name="status" id="status" value="Active" checked="checked"/>
    Active&nbsp; 
    <input type="radio" name="status" id="status" value="Closed"/>
    Closed
    </c:when>
    <c:otherwise>
    <input type="radio" name="status" id="status" value="Active" />
    Active&nbsp;
    <input type="radio" name="status" id="status" value="Closed" checked="checked"/>
    Closed
    </c:otherwise>
Run Code Online (Sandbox Code Playgroud)

我得到了两次不正确的结果.

谁能帮我这个?

Ale*_*lex 16

试试这种方式:

    <input type="radio" name="status" id="status"
     value="Active" ${posting.postingStatus=='Active'?'checked':''}>
Run Code Online (Sandbox Code Playgroud)