无法将记录从mysql数据库显示到jsp。 [英] not able to diplay records from mysql database to jsp.

查看:86
本文介绍了无法将记录从mysql数据库显示到jsp。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <%@   page     contentType   =  text / html    pageEncoding   =  UTF-8 %>  
<%@ page import = java.io。*,java .util。*,java.sql。* %>
<%@ page import = javax.servlet.http。* ,javax.servlet。* %>
<%@ taglib uri = http: //java.sun.com/jsp/jstl/core\" 前缀 = c %>
<%@ taglib uri = http://java.sun.com/jsp/jstl/sql 前缀 = sql % >

< html >
< head >
< title > SELECT操作< / title >
< / head < span class =code-keyword>>
< body >

< sql :setDataSource var = snapshot driver = com.mysql.jdbc.Driver

url = jdbc:mysql:// localhost:3306 / mysql

user = root 密码 = root / >

< sql:query dataSource = $ {snapshot} var = 结果 >
SELECT *来自user_reg_ml;
< / sql:query >

< table border = 1 >
< tr >
< ; th > ID < / th >
< ; th > 名称< / th >
< th > 电子邮件< / th >
< th > 国家< / th >
< / tr >
< c:forEach var = row items = $ {result.rows} >
< tr >
< td > < c:out value = $ {row.id} / > < / td >
< td > < <温泉n class =code-leadattribute> c:out value = $ {row.uname} / > < / td >
< td > < c:out value = $ {row.email} / > < / td >
< td > < < span class =code-leadattribute> c:out value = $ {row.country} / > < / td >
< / tr >
< / c:forEach >
< / table >
< b > 输入您要编辑的ID:< / b > < 输入 类型 = text name = txtsearchid = / >
< br / >
< 输入 类型 = 按钮 value = 搜索 / >
< sql:setDataSource var = snapshot 驱动程序 = com.mysql.jdbc.Driver url = jdbc:mysql:// localhost:3306 / mysql

user = root password = root / >
< sql:query dataSource = $ {snapshot} var = result >
SELECT * from user_reg_ml where id ='+ txtsearchid +';
< / sql:query >

< c:forEach var = row items = $ {res.rows} >
Id:< 输入 类型 = text 名称 = id value = $ {row.id} > < br / >

名称:< 输入 type = text 名称 = name value = $ {row.uname} > < ; br / >

电子邮件:< 输入 类型 = text 名称 = email value = $ {row.email} > < br / >

国家/地区: < input type = text 名称 = country value = $ {row.country} > < < span class =code-leadattribute> br / >
< / c:forEach >
< ; 输入 type < span class =code-keyword> = 提交 value = update >
< / body >
< / html >









这是我的代码。我想编辑选定的ID并更新它。但我甚至无法在文本框中显示它们。所以请任何人帮助我。

解决方案

{snapshot} var = result >
来自user_reg_ml的SELECT *;
< / sql :查询 >

< border = 1 >
< tr >
< th > ID < / th >
< th > 名称< / th >
< th > 电子邮件< / th >
< th > 国家< / th >
< / tr >
< c:forEach < span class =code-attribute> var = row items =


{result.rows} >
< tr >
< td > < c:out value =


{row.id} / > < / td >
< td > < c:out value =


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<html>
<head>
<title>SELECT Operation</title>
</head>
<body>

<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"

     url="jdbc:mysql://localhost:3306/mysql"

     user="root"  password="root"/>

<sql:query dataSource="${snapshot}" var="result">
SELECT * from user_reg_ml;
</sql:query>

<table border="1" >
<tr>
   <th>ID</th>
   <th>Name</th>
   <th>Email</th>
   <th>Country</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.uname}"/></td>
   <td><c:out value="${row.email}"/></td>
   <td><c:out value="${row.country}"/></td>
</tr>
</c:forEach>
</table>
              <b> Enter id you want to edit :</b> <input type="text" name="txtsearchid" value="" />
              <br/>
              <input type="button" value="Search"/>
              <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver url="jdbc:mysql://localhost:3306/mysql"

     user="root"  password="root"/>
        <sql:query dataSource="${snapshot}" var="result">
        SELECT * from user_reg_ml where id='"+ txtsearchid +"';
        </sql:query>

        <c:forEach var="row" items="${res.rows}">
            Id: <input type="text" name="id" value="${row.id}" ><br/>

            Name:  <input type="text" name="name" value="${row.uname}"><br/>

            Email: <input type="text" name="email" value="${row.email}"><br/>

            Country :<input type="text" name="country" value="${row.country}"><br/>
        </c:forEach>
        <input type="submit" value="update">
</body>
</html>





this is my code. I want to edit the selected id and update it. but i am not even able to display them in textbox. So please anyone help me out.

解决方案

{snapshot}" var="result"> SELECT * from user_reg_ml; </sql:query> <table border="1" > <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Country</th> </tr> <c:forEach var="row" items="


{result.rows}"> <tr> <td><c:out value="


{row.id}"/></td> <td><c:out value="


这篇关于无法将记录从mysql数据库显示到jsp。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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