开发者

on click of apply button save the respective value to database in jsp page

I am using jsp for printing the current openings in a page which is coming from Sql Server Database.

My code is:

<form method="post" action="">  
    <table align="left" border="0" cellspa开发者_开发问答cing="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>

Now I want to save the respective opening to a table on respective click on apply button. like I want to save the job code and position to the database.

How can I achieve this?


Use a servlet to process the data submitted from the JSP and save the data into a database from it.

There are many examples of code to do this: one of this is here

http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜