【问题标题】:dependent select list without reloading the jsp page不重新加载jsp页面的依赖选择列表
【发布时间】:2014-02-04 07:08:44
【问题描述】:

这是我在 jsp 中的依赖选择列表的代码。它工作正常,但它重新加载页面以获取第二个选择列表中的值。我想在不重新加载jsp的情况下做同样的事情。 请建议。

Javascript:

function change(){
var cid=document.getElementById("series_id").selectedIndex;
var val = document.getElementById("series_id").options[cid].text;
window.location.replace("HomePage_new.jsp?id="+val);
}

jsp:

 <!-- Series  --> 
<tr>
<td class="password">Series</td>
<td class="password"> 
<select id="series_id" name="series_id" onChange="change()" style="color: #4B616A; background-color: #eaeced; border: 1px solid #939fa4; height: 26px; width: 120px; padding-bottom: 4px; text-align: center;">
<option value="">Select</option>
<% 

while (rs.next())
{
    System.out.println("Series loop" + rs.getString(1));


%>
    <option value=""><% rs.getString(1); %><%= rs.getString(1) %></option>
        <%

         System.out.println("Series loop" + rs.getString(1));

    }

 %>
    </select></td>
</tr>

<!-- Drawing number  -->
    <tr>
        <td class="password">Drawing Number</td>
        <td class="password"><select id="dr_no_id" name="dr_no_id"
            style="color: #4B616A; background-color: #eaeced; border: 1px solid #939fa4; height: 26px; width: 120px; padding-bottom: 4px; text-align: center;">
            <%
            rs1 = stmt.executeQuery("select DISTINCT Drawing_No from series_details where Series='"+ request.getParameter("id") + "'");
            while (rs1.next()) 
            {
            application.setAttribute("Drawing No",rs1.getString(1));
            %>
            <option value="1"><% rs1.getString("Drawing_No");%><%= rs1.getString("Drawing_No") %></option>
            <%

            }

            %>
        </select></td>
    </tr>

已解决:

从此得到解决方案: http://www.javaquery.com/2011/07/how-to-get-value-from-database-without.html

【问题讨论】:

    标签: javascript jsp select


    【解决方案1】:

    回答为没有评论的声誉。

    您是否知道现在在页面上使用 JSP“内联”的方法被认为是不好的做法(自 2003 年发布 JSP 2.0 以来一直被认为是不好的做法)?

    查看最新的 Java EE JSP 教程:

    http://docs.oracle.com/javaee/5/tutorial/doc/bnagx.html

    将您的业务逻辑(填充列表的内容)移动到后端 servlet。

    然后您将能够显示列表而无需刷新。

    【讨论】:

      猜你喜欢
      • 2013-03-08
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多