JSP与JS在两个不同业面怎么传递值 JSP与JS在两个不同业面怎么传递值,请给我个例子好吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在二个页面间先由JSP完成传值,再由JSP给值JS. a.jsp<a href="b.jsp?name=xxx>Click to b.jsp</a>b.jsp<%String name = request.getParameter("name");%><script>var name = "<%=name%>" ;alert("hello "+name) ;</script> JSP页面<%@ page contentType="text/html; charset=gb2312" %><%@ page import="java.sql.*" %><%@ page import="java.util.*" %> <html> <body> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Cstar"; String user="sa"; String password="sa"; Connection conn= DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from Building"; ResultSet rs=stmt.executeQuery(sql);%> <% while(rs.next()){ %> <TR> <FORM ACTION="Query.jsp" METHOD="POST" name="Query"> <INPUT TYPE="button" name="button1" value="test" onclick="getValue();"> <input type="hidden" name="firstFiled" id="firstFiled" value="<%=rs.getString(1)%>"> <input type="hidden" name="secondFiled" id="secondFiled" value="<%=rs.getString(2)%>"> </TR> <% }%> </FORM> </body> </html><script>function getValue(){ var firstFiled = document.getElementById("firstFiled").value; var secondFiled = document.getElementById("secondFiled").value; alert(firstFiled); alert(secondFiled); }</script>JS页面Win1.document.writeln('<Query.jsp?method=" + firstFiled ">'); 调用JS的函数,由jsp页面将值作为参数传给js中的函数~ 首先<FORM ACTION="Query.jsp" METHOD="POST" name="Query"> 应该在while循环外部其次,你的hidden input可能有多个(因为循环取数据),这样你取到的var firstFiled = document.getElementById("firstFiled").value;是不确定的值,按照js,应该取的是第一条,不知道是不是你要的这个意图 你需要对hidden input加上id的序号但随之的问题,你通过一个button来遍历,可能要在function中写一个循环了 在while之前加一个计数器int counter = 0;while(rs.next()){couter++ ; //计数器加1............<input type="hidden" name="firstFiled" id="firstFiled<%=counter%>" value="<%=rs.getString(1)%>"><input type="hidden" name="secondFiled" id="secondFiled<%=counter%>" value="<%=rs.getString(2)%>">}<script>function getValue(){var counter = "<%=counter%>" ;for(var i=1; i<counter;i++){var firstFiled = document.getElementById("firstFiled"+counter).value;var secondFiled = document.getElementById("secondFiled"+counter).value;alert("第"+counter+"条记录的第一个值:"+firstFiled);alert("第"+counter+"条记录的第二个值:"+secondFiled);}}}</script> 在线等答案 jquery load() 请问jxl该如何安装? 如果使用JDBC-ODBC桥,是不是连接数据库的应用服务器只能是windows的 菜鸟问题,这段HTML怎样在FireFox达到IE中同样的效果? 细边框的样式 如何编写网页代码从而获取js中某个文本框的value?? JSP中的<jsp:useBean>出现问题请赐教?? 如何来把一个文件中的内容一下子取出来,谢谢,在线等! 本人想学jsp,想问几个关键的问题 又有事情向大家请教,问题可能简单的点,大家不要笑!! 网站架构的选择 关于梅花雪大师的树(JSP)的问题,请高手进!
b.jsp
<%
String name = request.getParameter("name");
%>
<script>
var name = "<%=name%>" ;
alert("hello "+name) ;
</script>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %> <html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Cstar"; String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from Building";
ResultSet rs=stmt.executeQuery(sql);%>
<% while(rs.next()){ %>
<TR>
<FORM ACTION="Query.jsp" METHOD="POST" name="Query">
<INPUT TYPE="button" name="button1" value="test" onclick="getValue();">
<input type="hidden" name="firstFiled" id="firstFiled" value="<%=rs.getString(1)%>">
<input type="hidden" name="secondFiled" id="secondFiled" value="<%=rs.getString(2)%>"> </TR>
<% }%> </FORM>
</body>
</html>
<script>
function getValue(){
var firstFiled = document.getElementById("firstFiled").value;
var secondFiled = document.getElementById("secondFiled").value;
alert(firstFiled);
alert(secondFiled);
}
</script>JS页面Win1.document.writeln('<Query.jsp?method=" + firstFiled ">');
int counter = 0;while(rs.next())
{
couter++ ; //计数器加1......
......
<input type="hidden" name="firstFiled" id="firstFiled<%=counter%>" value="<%=rs.getString(1)%>">
<input type="hidden" name="secondFiled" id="secondFiled<%=counter%>" value="<%=rs.getString(2)%>">
}<script>
function getValue(){
var counter = "<%=counter%>" ;
for(var i=1; i<counter;i++)
{
var firstFiled = document.getElementById("firstFiled"+counter).value;
var secondFiled = document.getElementById("secondFiled"+counter).value;
alert("第"+counter+"条记录的第一个值:"+firstFiled);
alert("第"+counter+"条记录的第二个值:"+secondFiled);
}
}}
</script>