页面取值以及或取下拉框的值(Ajax适用于ssh(Strtus1框架))

一、后台传递对象

public ActionForward getInvB(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception{

        List<TInvPlanDTO> list=invPlanService.getInvPlanName();
        request.setAttribute("list", list);
        return mapping.findForward("list");
    }

二、页面下拉框遍历属性值(第一种)
(1)

<td height="20" class="tr1px" style="width:400px;">
    <div align="right" class="style1">投标名称:</div>
</td>

<td class="tr1px style1">
                          <!-- 列表显示数据 foreach循环遍历-->
    <select id="planName" name="planName"  style="height:30px">
        <c:forEach var="item" items="${list }"> 
            <option value="${item.ipId}" >${item.planName}</option>
        </c:forEach>
    </select>
<td> 

效果图
这里写图片描述
(2)获取下拉框的值(jquery Ajax传递值给后台)

function  query(){

        var Arrt = new Array();
        var Arrd = new Array();
        var Arrd1 = new Array();
        //获取到下拉框
        var options=$("#planName option:selected"); 
        alert(options.val());
     $.ajax({
     //此url指向Action的方法(注意Ajax在Strtus1中的写法)
         url:"<%=basePath%>/pds/InvBoundaccptAction.do?method=getInvBoundaccpt",
         type:"GET",
         //.val()获取到属性值,点击请求会发送值到后台。
         data: {ipId:options.val()},
         dataType: "json",
         //result 代表下边方法封装好的json
         success : function(result) {

             for(var i=0;i<result.length;i++){
                 Arrt.push(result[i].invCompany);
                 Arrd.push(result[i].returnAmount) //退回保证金
                 Arrd1.push(result[i].accptAmount);//缴纳保证金

             }
}

(3)后台接收值(ssh框架 Strtus1框架)

public ActionForward getInvBoundaccpt(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception{
        TInvBoundaccptDTO dto = new TInvBoundaccptDTO();
        //通过request.getParmeter获取Ajax传递的值。
        String ipId =request.getParameter("ipId");
        if(ipId != null && !"".equals(ipId)){
            dto.setIpId(ipId);
        }
            List<TInvBoundaccptDTO> dtolist = invBoundaccptService.getTInvBoundaccpt(dto);
        //封装成json数据,传递给jsp页面(Ajax的result代表这个结果集)
        JSONArray json = JSONArray.fromObject(dtolist);
         PrintWriter out = response.getWriter();  
            out.println(json);  
            out.flush();  
            out.close();
        return null;
    }

三、第2种获取下拉框属性值(页面固定的值传给后台)
(1)

设置默认选中selected="selected"
<select id="protype" name="protype" style="width: 10%;height: 20px">
    <option value="" selected="selected"></option>
    <option value="职称信息" >职称信息</option>
    <option value="职业资格">职业资格</option>
</select>

(2)获取值

function queryFactoreval()
        {
        //获取下拉框的值
            var protype = document.getElementById("protype").value;
            var state = document.getElementById("state").value;
            var form = document.forms[0];
            //此代码拼接的参数有可能会乱码,参考方式如下
            form.action = "<%=basePath%>/emp/EmpProfessAction.do?method=getEmpProfess&protype="+protype+"&state="+state;
            form.submit();
        }
 //获取页面url传递的参数

    String str1= request.getParameter("protype");
    String str2= request.getParameter("state");
    String protype=“”;
    String state=“”;
    //处理页面传参乱码
    if(str1 != null && !"".equals(str1)){
        protype = new String(str1.getBytes("ISO-8859-1"),"GBK");
    }
    if(str2 != null && !"".equals(str2)){
        state = new String(str2.getBytes("ISO-8859-1"),"GBK");
    }

总结:strtus1 Ajax(注意)
(1)页面有n个Ajax请求,就必须写n个方法响应此请求。(注意Ajax是怎么返回数据到页面的)
(2)如果页面有request.setAttribute(“list”, list);必须先请求这个方法的url,传递数据到页面,然后再根据需求请求Ajax方法。
(3)主要在于前台页面如何获取下拉框的属性值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值