I am sending a id to controller from dropdown(oncgange function). It is working fine. Now in controller after querying from database result is stored in arrylist. i have given returntype arrylist. is it ok or there is any error. please help. i just want to display another dropdown based selected value of first dropdown. Suppose i selected Fruit , so i want to populate this in jsp.
<option value="mango">Mango</option>
<option value="pineapple">Pineapple</option>
jsp
<script>
function getScode()
{
var code = document.getElementById('code'),
code = code.value;
jQuery.ajax({
type: 'POST',
url: 'scode.htm',
data: {
code: code
},
success: function (html) {
$('#scode_data').html(html).show();
}
});
return false;
}
</script>
Select Genre
<select name="code" id="code" onchange="getScode();">
<option value="1">Fruit</option>
<option value="2">Game</option>
</select>
Under that
<div id="scode_data"></div>
controller
@RequestMapping(value="/scode", method = RequestMethod.POST)
public @ResponseBody ArrayList getScode(ModelMap modelMap, @RequestParam(value = "code", required = false) String code_val, HttpServletRequest request, HttpServletResponse response)
throws ClassNotFoundException {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource = new dbconnection.connection().getConnection(dataSource);
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "SELECT * FROM cat WHERE fcode='"+code_val+"'";
srs = jt.queryForRowSet(sql);
while (srs.next()) {
pojo obj2 = new pojo();
obj2.setScode(srs.getString("fcode"));
obj2.setSname(srs.getString("fname"));
arraylist.add(obj2);
}
return arraylist;
}