我有一个jsp页面的问题(我是新手)。 在一个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表点击“#”从通过选定的数值数据库中读取数据行。
我为基本的英语道歉! :/
建议不要在jsp中使用与servlet相关的代码。 – sudmong