0
我通過URL向另一個jsp頁面傳遞變量值,但是當我在第二個jsp頁面上運行System.out.println
來檢查變量值時,它始終爲空。使用url在jsp頁面之間發送變量
任何幫助表示讚賞。
下面的代碼是我的原始程序的片段,以減少羅嗦。
Testsend.jsp
<%@ page import ="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- Prints out Table header -->
<table border="1">
<tr>
<td>Title</td>
</tr>
<%
PreparedStatement pstmt;
pstmt = conn.prepareStatement("Select * from tadot");
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
out.println("<form action ='Testsend.jsp' method='post'");
out.println("<tr>");
out.println("<td>" + rs.getString("Title") + "</td>");
out.println("<td> <input type='hidden' name='hidden' value='"+rs.getString("Title")+"'> <input type='submit' name='editm' value='Edit'> </td>");
out.println("</tr>");
out.println("</form>");
}
String ed="";
// Check if edit button is clicked
if(request.getParameter("editm") != null) {
String getmov3 = request.getParameter("hidden");
// DEBUG - PRINTS OUT VALUE CORRECTLY
System.out.println("Testsend.jsp"+getmov3);
ed = getmov3;
// DEBUG - PRINTS OUT VALUE CORRECTLY
System.out.println(ed);
// Passes variable ed to Testrec.jsp
response.sendRedirect("Testrec.jsp?ed"+ed);
}
%>
</table>
</body>
</html>
Testrec.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import ="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String getmov2 = request.getParameter("ed");
// DEBUG - NULL VALUE PRINTED. ERROR.
System.out.println("Testrec.jsp"+getmov2);
%>
</body>
</html>
非常感謝。該死的只是錯過了一個標點符號,這讓我非常頭疼。 – iridescent