我正在使用jsp打印来自Sql Server数据库的页面中的当前空缺 我的代码是:
<form method="post" action="">
<table align="left" border="0" cellspacing="10" cellpadding="0">
<tr><td><input id="email" size="20" type ="hidden" value = "<%= session.getAttribute( "name" ) %>" name="email" /></td></tr>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%
java.sql.Connection con;
java.sql.Statement s;
java.sql.ResultSet rs;
java.sql.PreparedStatement pst;
con=null;
s=null;
pst=null;
rs=null;
try
{
con=DriverManager.getConnection("jdbc:jtds:sqlserver://W2K8SERVER:1433/career","user name","password" );
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String sql = "select * from currentopening";
try
{
s = con.createStatement();
rs = s.executeQuery(sql);
%>
<tr>
<td width="150" align="center"><b>Job Code</b> </td>
<td width="600" align="center"><b>Discription</b> </td>
<td width="600" align="center"><b>Position</b> </td>
</tr>
<%
int no=1;
while( rs.next() )
{
%>
<tr>
<td width="150" align="center"><input id="jobid" size = "2" type ="text" value = "<%= rs.getString("job_code") %>" name="jobid" /><%= rs.getString("job_code") %></td>
<td width="400" align="justify"><input id="pos1" type ="hidden" size = "2" value = "<%= rs.getString("position") %>" name="pos" /><%= rs.getString("discription") %></td>
<!--
<td width="400" align="center"><textarea name="dis" cols="40" rows="4" ><%= rs.getString("discription") %></textarea></td>
-->
<td width="400" align="center"><input id="pos" type ="text" size = "2" value = "<%= rs.getString("position") %>" name="pos" /><%= rs.getString("position") %></td>
<td width="100" align="center"><input type="submit" name="submit" value="Apply"/></td>
<td> </td>
</tr>
<%
no++;
}
%>
<%
}
catch(Exception e)
{
response.getWriter().println(e.getMessage());
}
finally
{
if(rs!=null) rs.close();
if(s!=null) s.close();
if(con!=null) con.close();
}
%>
</table>
</form>
现在我想在相应的点击应用按钮上将相应的开口保存到表格中。 我希望将作业代码和位置保存到数据库中。
我怎样才能做到这一点?
答案 0 :(得分:0)
使用servlet处理从JSP提交的数据,并将数据保存到数据库中。
有许多代码可以执行此操作:其中一个是
http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html