注册 登录
编程论坛 J2EE论坛

请问为什么我从表单输入数据库有的信息后转入到cometruejdbs_1.jsp后不能输出该信息的内容

tft 发布于 2020-10-21 15:43, 2898 次点击
下面是我的jdbc_1.jsp文件
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
    <form action="cometruejdbc_1.jsp" method="post">
        姓名<input type="text" name="Cname">
        <input type="submit" value="提交">
        <input type="reset" value="重置">
        
    </form>

</body>
</html>


下面是我的cometruejdbc_1.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<center>顾客信息表</center>
<%
    out.println("<table border= 1 align = center width= 700>");
    out.println("<tr>");
    out.println("<td align = center> 姓名 </td>");
    out.println("<td align = center> 电话号码 </td>");
    out.println("<td align = center> 住址 </td>");
    out.println("<td align = center> 已购器材 </td>");
    out.println("<td align = center> 应付金额 </td>");
    out.println("</tr>");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/commerce","root","xxx");
    PreparedStatement stmt = con.prepareStatement("select * from customer  where Cname like ?");
    String name = request.getParameter("Cname");
    stmt.setString(1,name);
    ResultSet rs = stmt.executeQuery();   
    while(rs.next())
    {
         out.println("<tr>");
         out.println("<td>"+rs.getString(1)+"</td>");
         out.println("<td>"+rs.getString(2)+"</td>");
         out.println("<td>"+rs.getString(3)+"</td>");
         out.println("<td>"+rs.getString(4)+"</td>");
         out.println("<td>"+rs.getString(5)+"</td>");
         out.println("</tr>");
    }
    out.println("</table>");
     rs.close();
     stmt.close();
     con.close();
 %>
</body>
</html>
1 回复
#2
tft2020-10-21 15:46
这是我的代码从表单输入信息后的情况
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
1