日期:2014-05-18  浏览次数:20722 次

【急求】怎么为<%%>中定义的值赋一个form中的值?
<%@   page   import= "org.infosys.common.CommonDictionary "     %>

<script   language= "javascript ">
<%
CommonDictionary   cd   =   new   CommonDictionary();
String   str=cd.getFlag( "document.getElementById( 'upId ').value ");
%>
</script>

这句话String   str=cd.getFlag( "document.getElementById( 'upId ').value ");的参数是form里的值,请问怎么在 <%%> 中用变量赋值啊?

谢谢各位帮忙!

------解决方案--------------------
不是很明白你的意思
获取form中的值 request.getParameter( "name ");
------解决方案--------------------
<input name= "upId " type= "text " value= " <%=str %> ">
------解决方案--------------------
<script language= "javascript ">
<%
CommonDictionary cd = new CommonDictionary();
String str=cd.getFlag( "%>

document.getElementById( 'upId ').value

<% ");
%>
</script>

看看行不行
------解决方案--------------------
<bean:define id=str name= " " property= "upId ">
<%String a = str.toString();%>
<script language= "javascript ">
<%
CommonDictionary cd = new CommonDictionary();
String str=a;
%>
</script>
------解决方案--------------------
<%%> 之外是客户端执行的
<%%> 之内是服务器执行的
------解决方案--------------------
所以在同一段代码中js中的变量( <%%> 外) 是不能直接赋值给服务器端的变量( <%%> 内)

要实现的话需要把客户端的变量提交到服务器再处理才行

------解决方案--------------------
<%!String str,str1 %>
<% str1 = document.getElementById( 'upId ').value;
CommonDictionary cd = new CommonDictionary();
String str=cd.getFlag(str1);
%>
如果document.getElementById( 'upId ').value;没有值的话就
<script>
var upId_Value = document.getElementById( 'upId ').value;
</script>
<%!String str,str1; %>
<% str1 = upId_Value ;
CommonDictionary cd = new CommonDictionary();
String str=cd.getFlag(str1);
%>
<% =str %> 可以显示出来这个值



------解决方案--------------------
你的做法是不能实现的。
<%%> 里面的内容是解析在服务器端的servlet,服务器端传过来的是HTTP块,不包含你的 <%%> 代码,也就是说HTTP标签的值与 <%%> 之间传值只能通过URL或者Form提交才能实现。
我不清楚你这么写这段代码的设计思路是什么,如果纯粹为了测试你可以放弃了。
如果一定要实现这种方式可以用Ajax,Javascript里面可以获取response返回的值,但这么做似乎不是你想要的。
这个问题不需要再讨论了,你如果把你想设计的逻辑内容说出来或许大家可以帮你,单纯从技术上,这种做法是错误的。
------解决方案--------------------
<html:text property= "upId " value= "333 "> </html:text>
谁说Struts标签没有value属性的,你自己查查去