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);
System.out.println("----------"+request.getParameter("method"));
System.out.println(!conn.isClosed());
%>
<FORM ACTION="Query.jsp" METHOD="POST" name="Query">
<% while(rs.next()){ %>
<TR align="center">
<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>
<% }%> <%
conn.close();
%>
</body>
</html>
<script>
function getValue(){ var firstFiled = document.getElementById("firstFiled").value;
var secondFiled = document.getElementById("secondFiled").value;
alert(firstFiled);
alert(secondFiled); }
</script>JS文件中的代码
function displayAttributeDataforDrill_Virt(theReplyArray) {
showRetrieveData();
var theFrame = "parent.MapFrame";
if ((useExternalWindow) || (!useTextFrame)) {
var Win1 = window.open("","QueryWindow","width=300,height=350,scrollbars=yes,resizable=yes"); theFrame = "opener";
if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
} else {
var Win1 = parent.TextFrame;
Win1.document.open();
}
Win1.document.location="http://zhongh:8080/app/Query.jsp?method= + firstFiled " ;///连接数据库
<%@ 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);
System.out.println("----------"+request.getParameter("method"));
System.out.println(!conn.isClosed());
%>
<FORM ACTION="Query.jsp" METHOD="POST" name="Query">
<% while(rs.next()){ %>
<TR align="center">
<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>
<% }%> <%
conn.close();
%>
</body>
</html>
<script>
function getValue(){ var firstFiled = document.getElementById("firstFiled").value;
var secondFiled = document.getElementById("secondFiled").value;
alert(firstFiled);
alert(secondFiled); }
</script>JS文件中的代码
function displayAttributeDataforDrill_Virt(theReplyArray) {
showRetrieveData();
var theFrame = "parent.MapFrame";
if ((useExternalWindow) || (!useTextFrame)) {
var Win1 = window.open("","QueryWindow","width=300,height=350,scrollbars=yes,resizable=yes"); theFrame = "opener";
if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
} else {
var Win1 = parent.TextFrame;
Win1.document.open();
}
Win1.document.location="http://zhongh:8080/app/Query.jsp?method= + firstFiled " ;///连接数据库
直接写在下面这个函数不行啊?
var firstFiled = document.getElementById("firstFiled").value;
<script language="javascript">
var firstFiled =<%=rs.getString(1)%>;
</script>
你试试
没达到要求?
不同文件吗? 这样试试???
没有空格
你要在js里面使用页面的上元素。
那你就要把页面上的这个参数传近来。或者你就直接把整个form传近来
<script type="text/javascript" src="../***.js"></script>
var firstFiled =document.forms[0].firstFiled .value;
..........
</script>
服务器端
String info = "www.beehoo.org";
response.getWriter().write(info);客户端
var obj = new ActiveXObject("Microsoft.XMLHTTP");
//特殊字符:+,%,&,=,?等的传输解决办法.字符串先用escape编码的.
obj.open("POST","beehoo.jsp",false);
obj.send();
//服务器端处理返回的是经过escape编码的字符串.
var strResult = unescape(oBao.responseText);
alert(strResult) ;这个可以不刷新网页的情况下,读取服务器端信息
欢迎访问 http://www.beehoo.org
服务器端
String info = "www.beehoo.org";
response.getWriter().write(info);客户端
var obj = new ActiveXObject("Microsoft.XMLHTTP");
//特殊字符:+,%,&,=,?等的传输解决办法.字符串先用escape编码的.
obj.open("POST","beehoo.jsp",false);
obj.send();
//服务器端处理返回的是经过escape编码的字符串.
var strResult = unescape(obj.responseText);
alert(strResult) ;这个可以不刷新网页的情况下,读取服务器端信息
欢迎访问 http://www.beehoo.org
<TR align="center">
<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>
<% }%>在这一段循环代码中,生成了多个相同ID的html组件,这是引起出错的原因,组件的id应该唯一,一种解决方法如下<% int count = 0;
while(rs.next()){ %>
<TR align="center">
<INPUT TYPE="button" name="button1" value="test" onclick="getValue(count);">
<input type="hidden" name="firstFiled" id="firstFiled"+count value="<%=rs.getString(1)%>">
<input type="hidden" name="secondFiled" id="secondFiled"+count value="<%=rs.getString(2)%>"></TR>
<% count++;
}%> <script>
function getValue(count){ var firstFiled = document.getElementById("firstFiled"+count).value;
var secondFiled = document.getElementById("secondFiled"+count).value;
alert(firstFiled);
alert(secondFiled); }
</script>