日期:2014-05-17  浏览次数:20632 次

Servlet和jsp的问题
现在有一个first.jsp、second.jsp和firstservlet.java。在first.jsp里面先servlet里面发了些请求。servlet从数据库取出数据并进行如下处理:request.setAttribute("test", test_num);
request.setAttribute("cstr", cstr);
request.setAttribute("jstr", jstr);
RequestDispatcher dispatcher=request.getRequestDispatcher("/second.jsp") ;
dispatcher.forward(request,response);
在secon.jsp里面有
<script type="text/javascript">
function ol()
{

<%
String[]cword=(String []) request.getAttribute("cstr");
int total=(Integer)request.getAttribute("test");
%>

for(var j =0; j<total; j++) 
{
var x=document.getElementById("myTable").insertRow(1);
var y=x.insertCell(0);
var tt=document.createElement("input");
tt.type="text";
tt.id="as"+j;
tt.name="tname";
//y.innerHTML=t_arry[j];
y.innerHTML=cword[j];
var obj=x.appendChild(tt);
}
}
</script>
<body bgcolor="grey" onload="ol()" >

为什么不能绘制表格?求教啊。。。大神。。。。

------解决方案--------------------
<%
String[]cword=(String []) request.getAttribute("cstr");
int total=(Integer)request.getAttribute("test");
%>

取出的这俩个变量不能直接写在js 中吧。
for(var j =0; j<[color=#FF00FF]total; j++) [/color]
total 这个变量 你换成<%=total %> 这么写 
其他类似
你试试
------解决方案--------------------
没问题的 js里面也可以写 <%=value%> 的 ,