Struts2-使用jQueryAjax从数据库加载信息

Struts2-使用jQueryAjax从数据库加载信息,ajax,hibernate,jquery,struts2,Ajax,Hibernate,Jquery,Struts2,为了开发我的webApp,我使用struts 2 hibernate 3,我想在更改值时运行一个查询​​在标记中,并将此查询的结果传递到隐藏的输入中 当select标记的元素发生更改时,我希望保持在同一页面中 我的页面jsp文件如下示例所示: <form name="evalform" action="saveOrUpdateSousEval" method="post" > <s:iterator begin="1" end="4" status="stat

为了开发我的webApp,我使用struts 2 hibernate 3,我想在更改值时运行一个查询​​在标记中,并将此查询的结果传递到隐藏的输入中 当select标记的元素发生更改时,我希望保持在同一页面中

我的页面jsp文件如下示例所示:

<form  name="evalform" action="saveOrUpdateSousEval"    method="post"  >    
<s:iterator begin="1" end="4" status="status">
        <s:hidden   name="SousEval_Note"   
                value="99" 
                placeholder="entrer  Note"
                      />
        <s:select 
            headerValue="---------------- Select ---------------"
            headerKey="-1" 
            list="SousItemsListGrille"
            listKey="SousItem_ID"   
            listValue="SousItem_Libelle"
            name="sousEvalItem.SousItem_ID"  
            cssClass="selectedId"

            />

</s:iterator>   
</form> 
在这里,我首先获取所选元素的id:

    <script type="text/javascript">
        $("#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 !!
    });
    });
    </script>
在struts中。xmli定义此操作:

<action name="ponderation" method="getItembyPonderation"        class="action.classAction">
    <result name="success"    >/oki.jsp</result>
 </action>
在我的集体诉讼中,我有以下方法:

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

public List<Double> selectponderation(Long idsousitem){
    List<Double> 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;
}
在这里,我需要一个这样做的想法

 <script type="text/javascript">
        $("#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({
        url : 'your_action name_where_you_execute_query',
        data:{
            idd:idd
        },
        type : 'GET',
        dataType : 'as_you_want_from_your_action'

    });
 });
    </script>
上面的示例演示了如何调用一个操作并将参数传递给该操作。
你明白了吗?

请告诉我确切的问题是什么?我不明白。@Aniket我想问题在于调用ajax,但操作应该返回oki.jsp。问题是我不知道如何处理查询的加载结果,并将其放入隐藏的输入中,并保持在同一个ok.jsp中,因为我有许多标记select@Aniket是的,诸如此类,但我刚刚找到了一个其他的解决方案。我很高兴得到你们的支持问题解决了如果您满意,那么您能将此答案标记为已验证吗?接受答案:它是如何工作的?接受答案很重要,因为它既可以奖励解决问题的海报,也可以告知其他人问题已经解决。您可以选择您提出的问题的任何答案作为接受答案。一次只能有一个答案是“已接受”答案。当你不能接受答案时,在提问后15分钟内会有一段短暂的时间。要将答案标记为已接受,请单击答案旁边的复选标记,将其从空心切换为绿色。