在jsp中把隐藏域的值传到java后台


不用from表单怎么把这个隐藏域的值传到action里面去,这个值是动态的会变

打个比方,你用的是struts2获取动态变量:
);">sub

那么你的js函数:
function sub(str){
这里你就可以使用ajax来动态提交表单
}

或者一个简单方法:

这个可以使用AJAX

使用JS获取这个值,然后将这个值以get或者post的方式提交给后台的action

可以用 ajax的方式,或者get的方式都可以传到后台
get的方式就是 xxx.do?pp=ss

你如果只要在后台得到值的话,还是很简单的
实例:

// 页面初始化
$(function() {
// 得到隐藏域的值
var value=$("#tagEweb").val();
$.get("action地址",{tagEweb:value} function(data){
alert("Data Loaded: " + data);
});
});
上面是jquery的ajax的get请求
在后台你只要用 request.getParameter("tagEweb");就是你要得到的值false了

这个值的值是动态的,以标签或者变量的形式,当做参数,放到aciton的url里,

src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar212&tagEweb=false

在这后面加一个参数就可以了

[quote]我在jsp页面里 src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar212"
放了其它的参数 现在要加一个隐藏域的值 [/quote]

var tagEweb = document.getElementById("tagEweb").value;
src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar212&tagEweb="+"tagEweb";

可以,直接放在URL里面就可以了

第一、如果是动态的值 ,你只要改变

jquery里面的值就不要改变 还是一样的
第二、如果不知这一个参数你只要在后面加就行了
$.get("action地址",{tagEweb:value,name:第二个值} function(data){
}

src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar212&tagEweb=false

就是这样放就行了

&tagEweb=false

在你的原URL后面添加这个

jquery ajax,比如tagEweb值发生变化的时候自动ajax提交到action

[code="java"]$("#tagEweb").change(function(){
$.ajax(function(){
url : "xxx.action",
data: "hiddenValue="+ $("#tagEweb").val();
method: "post"
});
});[/code]

[quote]这个引用的 能不用js可以直接放在页面里传过去吗?[/quote]
不用js。。。。可能性不大

你的值不是true就是false你就判断啊

是这个用法,具体的你可以使用JS给他拼接过去

[quote]我是用 src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar214
&tagEweb= 方法1:
[code="java"]
src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar214
&tagEweb="
width="100%" height="320" scrolling="no" frameborder="0"
marginheight="0" marginwidth="0">
[/code]

方法2:
用js写
[code="java"]
var tagEweb = document.getElementById("tagEweb").value;
document.getElementById("zs").src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar212&tagEweb="+"tagEweb";
[/code]

[quote]bean:write 这个标签不能用 [/quote]

你用什么MVC框架?Spring MVC

[quote] src="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar214
&tagEweb=${formBean.tagEweb}"/>"

width="100%" height="320" scrolling="no" frameborder="0"

marginheight="0" marginwidth="0"> [/quote]
这样也可以啊

那就用EL表达式 ${formBean.tagEweb} 也是可以的

[quote]="${request.contextPath}/kbs/c_showEwebEiditor.action?serviceId=${serviceRequest.serviceId}&tagId=serviceInfoChar214

&tagEweb=${formBean.tagEweb}"/[/quote]

tagEweb 这个必须是formBean的一个属性,要不然没有没法用EL表达式

2种方式啊,一是Java赋值(EL表达式),一是页面赋值(html,js)
没有其他的办法了