从JSP向HTML文本框分配值 [英] Assign value to HTML textbox from JSP

查看:150
本文介绍了从JSP向HTML文本框分配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在创建一个网页来添加有关给定产品的一些信息.我需要输入id,名称,描述和图像作为信息.我需要自动生成id.我正在使用jsp和数据库作为访问权限.我正在从数据库中获取count(*)+ 1值并分配给我的html文本框,但显示为null.我可以寻求帮助吗?

Hello I am creating a web page to add some information about given product.I need to enter id,name,description and image as information.I need the id to be auto generated.I am using jsp and database as access.I am fetching the count(*)+1 value from database and assigning to my html text box but its showing as null.can i get some help?

代码:

<body>
<%@page import="java.sql.*"%>
<%! String no; %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:pd");
ResultSet rs = null;
Statement st = con.createStatement();
String sql = ("select count(*)+1 from products");
st.executeUpdate(sql);
while (rs.next()) { 
no=rs.getString("count(*)+1");
}
rs.close();
st.close();
con.close();
}
catch(Exception e){}
%> 
<Form name='Form1' action="productcode.jsp" method="post">
<table width="1024" border="0">
  <tr>
    <td width="10">&nbsp;</td>
    <td width="126">Add Product: </td>
    <td width="277">&nbsp;</td>
    <td width="583">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Product Id:</td>
    <td><label>
      <input type="text" name="id" value="<%= no%>"/>
    </label></td>
    <td>&nbsp;</td> 
.... and so on

推荐答案

您编写了一个查询来获取这样的数据

You wrote a query to get the data like this

          String sql = ("select count(*)+1 from products");
          st.executeUpdate(sql);

声明

            executeUpdate()

仅用于执行INSERT,UPDATE之类的操作

only used to do the operations like INSERT,UPDATE

尝试

             rs=st.executeQuery(sql); 

代替executeUpdate()

instead of executeUpdate()

这篇关于从JSP向HTML文本框分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆