我目前正在为一个大学项目。我有将从数据库显示的记录行。我想要的是,当选中单选按钮的特定行,然后单击该按钮时,选中的行将出现在另一个jsp页面上。如果有人可以帮助,将不胜感激。已经坚持了一段时间。这是GUI的图片。 GUI
行的代码在这里
<sql:setDataSource
var="myDS"
driver="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/FYP?autoReconnect=true&useSSL=false"
user="root" password="Ucc*62229"
/>
<sql:query var="listUsers" dataSource="${myDS}">
SELECT * FROM Trainer_Time;
</sql:query>
<div align="center">
<table border="1" cellpadding="5">
<caption><h2>List of Tutors</h2></caption>
<tr>
<th>Select</th>
<th>Email</th>
<th>Sport</th>
<th>Location</th>
<th> PRICE - € </th>
<th>Day 1</th>
<th>Day 2</th>
<th>Day 3</th>
<th>Timeslot 1</th>
<th>Timeslot 2</th>
<th>Timeslot 3</th>
</tr>
<c:forEach var="Trainer_Time" items="${listUsers.rows}">
<tr>
<td><input type="radio" name= "myradio" value="0"/>. <c:out value="${Trainer_Time.id}" /></td>
<td><c:out value="${Trainer_Time.email}" /></td>
<td><c:out value="${Trainer_Time.sport}" /></td>
<td><c:out value="${Trainer_Time.location}" /></td>
<td><c:out value="${Trainer_Time.price}" /></td>
<td><c:out value="${Trainer_Time.day1}" /></td>
<td><c:out value="${Trainer_Time.day2}" /></td>
<td><c:out value="${Trainer_Time.day3}" /></td>
<td><c:out value="${Trainer_Time.timeslot1}" /></td>
<td><c:out value="${Trainer_Time.timeslot2}" /></td>
<td><c:out value="${Trainer_Time.timeslot3}" /></td>
</tr>
</c:forEach>
</table>
</div>
<div class="form"><form action="book.jsp" method="post">
<p>
<input type="submit" name="button" id="button" value="Book" />
`
下一个JSP页面的代码在这里;
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*" %>
<%
int id = 0;
String email=request.getParameter("email");
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost:3306/FYP?autoReconnect=true&useSSL=false";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "Ucc*62229");
Statement preparedStmt= conn.createStatement();
ResultSet rs=preparedStmt.executeQuery("select * from Trainer_Time where id='"+id+"'");
String type=request.getParameter("myradio");
try{
out.println(""+rs.getString("id")+ "");
} catch(Exception e)
{
out.println("<h1>"+"Server Error"+ e+ "<h1>");
}
%>