I have a problem with a jsp page (I m a novice). In a jsp page, I wrote a table that is read from a database. I write here the code of the page:
<%@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
"+
"from fimand
"+
"where eser=2012
"+
"group by numelencotrasm,dtelencotrasm
"+
"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-able 点击, 从数据库中读取数据, 传递选定行的值 。
我为基本的英语道歉!