我的 jsp 页面有问题(我是新手)。在一个jsp页面中,我写了一个从数据库中读取的表。我在这里写页面的代码:
<%@page import="java.sql.SQLException"%>
<%@page import="java.lang.String"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.util.Date "%>
<%@page import="jord.ConnectionManager "%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
String sql= "select numelencotrasm,dtelencotrasm \n"+
"from fimand \n"+
"where eser=2012 \n"+
"group by numelencotrasm,dtelencotrasm \n"+
"order by numelencotrasm";
ConnectionManager manager = new ConnectionManager();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
conn = manager.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException ex){
rs.close();
conn.close();
rs=null;
conn=null;
response.sendRedirect("../index.jsp");
}
%>
<form id="tabella1" name="tabella1">
<input name="numelencotrasm" type="hidden" value=""/>
<input name="dtelencotrasm" type="hidden" value=""/>
<table width="275px" cellspacing="0" cellpadding="1" border="1">
<tr>
<td class="TabellaTitolo" width="50%">
Numero Distinta
</td>
<td class="TabellaTitolo" width="50%">
Data Distinta
</td>
<td class="TabellaTitolo" width="50%">
#
</td>
</tr>
<%
try{
while(rs.next()){
%>
<tr>
<td>
<input type="text" value="<% out.print(rs.getInt(1)); %>"/>
</td>
<td>
<input type="text" value="<% out.print(rs.getDate(2)); %>"/>
</td>
<td>
<a href="#" onclick="javascript:setValue('<% out.print(rs.getInt(1)); %>','<% out.print(rs.getDate(2));%>');">
Click-me
</a>
</td>
</tr>
<%
}
}catch(Exception e){
response.sendRedirect("../index.jsp");
}
%>
</table>
</form>
<script language="Javascript">
function setValue(num, dt){
document.tabella1.numelencotrasm.value=num;
document.tabella1.dtelencotrasm.value=dt;
alert(document.tabella1.numelencotrasm.value); //test
alert(document.tabella1.dtelencotrasm.value);//test
}
</script>
好吧..我现在要创建一个新的html-table 点击行“#”从数据库中读取数据并传递所选行的值。
我为基本的英语道歉!:/