jsp,action,jsp之间多参数值的传递

2 篇文章 0 订阅
1 篇文章 0 订阅

1.jsp展示如下:

      

2.jsp模拟电影座位的选座功能

功能实现:

   点击“选择位置”按钮,即可将填写的内容“b2”和主键did通过url一起传送给action,如下:

 <th data-options="field:'c',width:200,formatter:formatterrollbackreason">存放房间号</th>

<th data-options="field:'did',width:100,formatter:formatterrollback">选择位置</th>

 

/*

*按钮点击事件触发函数,在此一定要特别注意href中引号的使用,因为这点问题,找了好久的错误

*/

 function onclickFunction(values){

    var place=document.getElementById("place").value;

    window.location.href='${ pageContext.request.contextPath }/secdocument_place.action?did='+values+'&place='+place;    

      }

      

/*

*按钮样式

*/

      function formatterrollback(value, row, Index)

      {

       var str = "<input type='submit' value='选择位置' οnclick=onclickFunction("+value+")>";  

       return str;         

      }

      

/*

*输入框样式

*/

      function formatterrollbackreason(value, row, Index)

      {

       var str = "<input  id='place' style='font-family:'楷体';font-size:13px;width:140px;' name='place' type='text'  placeholder='请输入相应的房间号'/>";  

       return str;         

      }

    

secdocument_place.action

 

public String place(){

       //通过ServletActionContext.getRequest().getParameter获得url中的两个参数值

 

 

String did = ServletActionContext.getRequest().getParameter("did");
String place = ServletActionContext.getRequest().getParameter("place");

 

 

ActionContext actionContext = ActionContext.getContext();

        //将值分别用以下方式进行存储,并在showplace.jsp中进行调用

 

Map<String, Object> request = (Map) actionContext.get("request");
request.put("did", did);
System.out.println("request.get(key):"+request.get("did"));

Map<String,Object> session = ActionContext.getContext().getSession();
session.put("place", place);
System.out.println("request.get(place):"+session.get("place"));

 

    return "showplace";

 

}

 

showplace.jsp

//从action获得did和place的两个参数值,因为place值为strin类型,所以,要加引号,否则会出错

 

<div class="confirm-btn disable" data-act="confirm-click" data-bid="b_0a0ep6pp" οnclick="Click(${did},'${sessionScope.place}')">

 

        确认位置

 

</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/cinemas-seat.f35e64e9.js"></script>

cinemas-seat.f35e64e9.js如下:

var did=""
var place=""
var row=""
var colum=""
function Click(str,plac){
did = str;
place=plac;

}

  $(".confirm-btn").on("click",
        function(e) {               
          var url = '${ pageContext.request.contextPath }/secdocument_setplace.action';
          $.ajax({
              type: "post",
              url: url,
             data: {"did":parseInt(did),"place":place+'存档室-'+row + '排' + colum + '列'}, 
              cache: false,
              async : true,
             success: function ()
              {  alert("保存成功!")

            // window.location.reload(); //刷新当前页面 

                 //保存成功则自动返回如下页面:

 

            window.location.href='${ pageContext.request.contextPath }/secdocument_secUnplace.action';
              }, 
               error:function (XMLHttpRequest, textStatus, errorThrown) {      
                  alert("请求失败!");
              } 
           });

 

        }),

secdocument_setplace.action

public String setplace(){
String place = ServletActionContext.getRequest().getParameter("place");
System.out.println("存放位置为:"+place);
String did = ServletActionContext.getRequest().getParameter("did");

System.out.println("传送过来的did值为 :"+did);

 

Document existDocument= documentService.checkState(Integer.parseInt(did));

// 判断
if (existDocument != null) {
existDocument.setSectime(new Date());
existDocument.setPlace(place);
documentService.update(existDocument);
}
return NONE;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值