ADF页面片段中借助javascript使用Form提交Post请求

本文介绍了一种在页面片段中通过JavaScript动态创建form元素的方法,以此实现POST请求并传递参数。这种方法尤其适用于不能直接嵌套form标签的情况。文章还提到了在特定框架下,不同URL路径对接收POST参数的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于在页面片段中不能直接添加form标签,因为整个页面片段处于一个大的form标签之中,而form标签不能嵌套,有时候我们需要在页面片段中提交一个post请求,并跳转到其他URL时可以借助javascript的dom来生成一个form。

[html]  view plain copy
  1. <af:goButton text="Go Button" id="gb1">  
  2.           <af:clientAttribute name="userName" value="aaaaaaaaaa"/>  
  3.           <af:clientListener type="click" method="openPostWindow"/>  
  4.         </af:goButton>  

例如在以上的Go Button中添加一个javascript的 click事件,打开一个post请求,并且将参数userName传给请求。

javascript代码如下:

[javascript]  view plain copy
  1. function openPostWindow(e) {  
  2.     var button = e.getSource();  
  3.     var newForm = document.createElement("form");  
  4.     newForm.id = "postForm";  
  5.     newForm.action = "http://showing:7101/PostRequestDemo/postrequestadapterservlet";  
  6.     newForm.target = "_blank";  
  7.     newForm.method = "post";  
  8.     var usernameInput = document.createElement("input");  
  9.     usernameInput.name = "userName";  
  10.     usernameInput.type = "hidden";  
  11.     usernameInput.value = button.getProperty("userName");  
  12.     newForm.appendChild(usernameInput);  
  13.     document.body.appendChild(newForm);  
  14.     newForm.submit();  
  15.     document.body.removeChild(newForm);  
  16. }  
如此变可以提交post请求了。另外发现在ADF中,当URL地址中为faces时,不能接收post请求的参数,只能接收get方法提交的参数。

例如将上述javascript中的http://showing:7101/PostRequestDemo/postrequestadapterservlet改为http://showing:7101/PostRequestDemo/faces/postrequestadapterservlet
时,就接收不到userName参数了。

转自:http://blog.csdn.net/ygj26/article/details/8067940

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值