日期:2014-05-18  浏览次数:20800 次

JSP小问题40分;

<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   language= "java "   import= "java.sql.* "%>

<html>
    <head>
     
    </head>
   
    <body>
    <%   String   id=request.getParameter( "id ");id   =   new   String(id.getBytes( "ISO8859_1 "), "gb2312 ");%>
    <%=id%>
     
      <%
      Class.forName( "org.gjt.mm.mysql.Driver ").newInstance();  
String   url   = "jdbc:mysql://localhost:3306/paper?useUnicode=true&characterEncoding=gbk ";
Connection   conn=   DriverManager.getConnection(url);  
Statement   stmt=conn.createStatement();
String   sql   =   "select   *   from   student   where   sname= ' "+id+ " ' ";
ResultSet   rs=stmt.executeQuery(sql);
String   sql2= " ";
if   (rs.next())   {
sql2   =     rs.getString(4);}%>


<input   type   = "text "   name   =   "textname "   value   =   " <%=sql2%> "> <br>   <br>
  <%rs.close();
  stmt.close();
conn.close();
    %>
    </body>
</html>

-----------------------------

value   =   " <%=sql2%> ",在数据库得到参数,显示在     TEXT里           我要在TEXT里输入新的参数,传到数据库里替代刚得到,怎么弄呢?


就是修改数据库的一个字段!


------解决方案--------------------
lz其实可以自己写出来,把 <input type = "text " name = "textname " value = " <%=sql2%> "> 加到一个 <form> </form> 中,再上加个 <input type= "hidden " name= "id " value= " <%=id%> "/> ,然后把sql语句改为:update student ......