Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp struts2列表框中的默认值_Jsp_Listbox_Struts2_Struts_Jsp Tags - Fatal编程技术网

Jsp struts2列表框中的默认值

Jsp struts2列表框中的默认值,jsp,listbox,struts2,struts,jsp-tags,Jsp,Listbox,Struts2,Struts,Jsp Tags,我们有列表框。这将显示美国的不同状态。我想州“LA”应该是预选的。但我不知道“LA”在列表中的位置。它可能会有所不同。我们正在为此使用以下脚本 <select id="state" name="state" title="State" class="js_required prompt_text grid_2" tabindex="5"> <option>State</option> <s:

我们有列表框。这将显示美国的不同状态。我想州“LA”应该是预选的。但我不知道“LA”在列表中的位置。它可能会有所不同。我们正在为此使用以下脚本

<select id="state" name="state" title="State" class="js_required prompt_text grid_2" tabindex="5">
                <option>State</option>
                <s:iterator value="@com.homeservices.action.utils.StateCode@values()">
                    <option value="<s:property/>"><s:property/></option>
                </s:iterator>
</select>
……等等


有人能建议如何将LA作为预选状态。

将此脚本放在
之前,然后填充
状态

<script type="text/javascript">
        document.getElementById("state").value = "LA";
</script>

document.getElementById(“state”).value=“LA”;
Struts方法

JSP方法(JSTL/JSP-EL)

陈述
${state}

看起来更像是一种变通方法,而不是真正的解决方案。如果Struts2真的不可能做到这一点,我会非常惊讶。我所知道的所有其他MVC框架都肯定支持这一点。是的,若我们把它放在网页的末尾,它就会执行。因为他想选择不是索引的LA。或者他可能会和

<script type="text/javascript">
        document.getElementById("state").value = "LA";
</script>
<s:select id="state"
          name="state"
          title="State"
          headerKey=""
          headerValue="State"
          list="@action.StateCode@values()"
          cssClass="js_required prompt_text grid_2"
          value="@action.StateCode@LA"
          tabindex="5"/>
<%@ page import="action.StateCode" %>
<c:set var="states" value="<%=StateCode.values()%>"/>

<select id="state" name="state" title="State"
        class="js_required prompt_text grid_2" tabindex="5">
    <option>State</option>
    <c:forEach items="${states}" var="state">
        <option value="${state}" ${state == 'LA' ? 'selected="selected"' : ''}>${state}</option>
    </c:forEach>
</select>