How to get state in jsp how to write of two implementations
- 2020-05-27 06:53:17
- OfStack
Today, when I was writing a project, I encountered this problem. Since the framework was built in 2005, jsp could not store labels, and only java code could be used to write. The following is the example I wrote.
It also describes the use of tags in jsp
Write the java code in jsp
Method 1:
Status:
Method 2:
Reference the tag in jsp
It also describes the use of tags in jsp
Write the java code in jsp
Method 1:
Status:
<select name="states">
<option value="0" <%="0".equalsIgnoreCase(states)?"selected":"" %>> available </option>
<option value="1" <%="1".equalsIgnoreCase(states)?"selected":"" %>> Do not use </option>
</select>
Method 2:
<tr>
<td align="right" bgcolor="f0f8ff" class="title-td1"> state </td>
<td colspan="2" class="title-td2">
<select name="status" id="status">
<option value="">== Please select a ==</option>
<option value="0" <%if(log.getStatus().equals("0")){ %> selected <% }%>> disable </option>
<option value="1" <%if(log.getStatus().equals("1")){ %> selected <% }%>> normal </option>
</select>
</td>
</tr>
Reference the tag in jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<tr>
<td height="23" align="right" class="td3"> class Type: </td>
<td align="left" class="td4">
<select name="state" class="search_input" onfocus="this.si=this.selectedIndex;" onchange="this.selectedIndex=this.si;">
<option value="">== Please select a ==</option>
<option value=" Residents' committees "<c:if test="${smsname.state==' Residents' committees '}">selected</c:if> > Residents' committees </option>
<option value=" community " <c:if test="${smsname.state==' community '}">selected</c:if>> community </option>
</select>
</td>
</tr>