Struts2 – 使用jquery ajax从数据库加载信息

用于开发我的webApp我使用struts 2 hibernate 3并且我想在更改标记中的值并在隐藏输入中传递此查询的结果时运行查询,我想留在改变select标签的元素时的同一页面

我的页面jsp就像这个例子一样:

 

在这里,我首先得到选择的元素的id:

   $("#idselectdiv .selectedId").change(function () { var idd = $(this).val(); //each element selected in each select tag has an id and i want excute query of this id alert(" id selected "+idd); $.ajax({ //somthing here !! }); });  

在struts中。 xmli定义此操作:

  /oki.jsp  

在我的class级动作我有这个方法:

 public Double getItembyPonderation(){ System.out.print("enter getItembyPonderation ok"); Double b = null; HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); List a=selectponder.selectponderation(Long.parseLong(request.getParameter("SousItem_ID"))); while (a != null) { return b=a.get(0); } return b; } 

在我class上道:

 public List selectponderation(Long idsousitem){ List valponderation = null; try { valponderation = session.createQuery("SELECT a.ponderation FROM items a, sousitems b WHERE a.Item_ID = b.Item_ID and b.SousItem_ID="+idsousitem).list(); ; } catch (Exception e) {e.printStackTrace();} return valponderation; } 

在这里,我需要一个想法

   

以上是如何调用操作并将参数传递给该操作的示例。 你明白了吗?