简体   繁体   English

无法从数据库中获取数据

[英]Unable to fetch data from database

See a code below: 请参阅下面的代码:

<label>Subject:</label>
<s:select onchange = "form1.submit();" 
             theme = "simple" 
              list = "#{'':'All','E':'English','M':'Maths','S':'Science','H':'Humanities'}" 
              name = "Subject" 
                id = "Subject"  />

But when I change drop-down to E(English) when page loads, drop-down changes to 'ALL' and data is also not showing. 但是,当页面加载时我将下拉列表更改为E(英语)时,下拉列表更改为“ ALL”,并且数据也未显示。

When you change drop-down to E(English) the change event happens and you have used onchange event handler which submits the form to the server. 当您将下拉菜单更改为E(English)时, change发生change事件,并且您使用了onchange事件处理程序,该处理程序将表单提交给服务器。 The server returns the page back to the client but it doesn't know the value it should set because it's not set. 服务器将页面返回给客户端,但由于未设置,因此不知道应设置的值。 You should either change the event handler to not submit the form at least with the ordinal request or use ajax to send the data, or create getters and setters for the named field to hold the value of the key in the list. 您应该更改事件处理程序,使其至少不与顺序请求一起提交表单,或者使用ajax发送数据,或者为命名字段创建getter和setter,以将键的值保存在列表中。 Also you can't use empty keys as values of the list, because it doesn't match the selected key. 另外,您不能将空键用作列表的值,因为它与所选键不匹配。 You can also use a value attribute of the s:select tag to pre-select the value from the list. 您还可以使用s:select标记的value属性从列表中预选择值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM