我通过URL将变量值传递给另一个jsp页面,但是当我在第二个jsp页面上运行System.out.println
来检查变量值时,它始终为null。
感谢任何帮助。
下面的代码是我原始程序的片段,以减少它的冗长。
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>
答案 0 :(得分:1)
看起来你错过了"="
response.sendRedirect("Testrec.jsp?ed="+ed);