I have created a json object of state after getting data from database in a jsp file and now i want to add value from json file to combobox. can anyone tell me how to add value in combobox. my code of Example.jsp file where i creates json object is
try{
String query="SELECT * from State";
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jums","root","abcdefgh");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
JSONArray list = new JSONArray();
while(rs.next())
{
//int id=rs.getInt("id");
//String name=rs.getString("name");
JSONObject jObj = new JSONObject();
jObj.put("id", rs.getInt("id"));
jObj.put("name", rs.getString("name"));
list.add(jObj);
}
out.print(list);
conn.close();
}catch(Exception ex)
{
ex.printStackTrace();
System.out.println("Error: "+ex.getMessage());
}
and i want to load name of state in a some other jsp file having combobox with code as
<input class="easyui-combobox" name="language" style="width:100%;" data-options="
valueField:'id',
textField:'name',
url:'EXAMPLE.jsp',
label: 'State:',
labelPosition: 'top'
">
but i am not getting the name of state. Please help
EasyUI comboboxes accept data strictly in this json format:
[{"id":"1","name":"name_1"},{"id":"2","name":"name_2"}]
double quotes " " included
Thus if you're populating your json data from a Java class, ensure that you add the double quotes in side the string as well, like: