`

Javascript动态生成Form表单

阅读更多

主要是在利用Struts中的DispatchAction开发的使用,用于隐藏方法参数。因为在使用DispatchAction的时候,可能在地址栏会暴露后台方法名,所以采用了这种动态生成Form表单,并利用Post方式提交的方法对DispatchAction中的方法参数进行隐藏。这样在超链接或者利用button进行提交的时候可以在一定程序上对后台代码方法进行隐藏。当然这种方法也并不能做到绝对的方法隐藏,只是在某种程度上能起到一定的效果。以下是Javascript代码:

 

function forward(methodName){
        //create a form
 	var tempForm = document.createElement("form");
 	tempForm.action="/question.do";
 	tempForm.method="post";
 	document.body.appendChild(tempForm);
 	 
       //create a submit button  
	var tempInput = document.createElement("input");
	tempInput.type="hidden";
	tempInput.name="method";  
	tempInput.value=methodName;  //the parameter of method in the code of DispatchAction.
	
	tempForm.appendChild(tempInput);
       //submit the form
	tempForm.submit();
}

 当然,还可以对以上代码进行改写,在此只提供一种思路。

分享到:
评论
3 楼 xiaofengtoo 2009-04-16  
非常恳请 给个简单的DEMO 谢谢 !!!!!
2 楼 xiaofengtoo 2009-04-16  
我现在使用的DispatchAction  在表单提交的 时候也有方法名称出现 不知道是否我哪里配置有无还是写法有无 ?
1 楼 xiaofengtoo 2009-04-16  
兄台  可否   给个点的实例 

相关推荐

Global site tag (gtag.js) - Google Analytics