0

I am passing a variable value via URL to another jsp page, but when I run a System.out.println on the 2nd jsp page to check the variable value, it is always null.

Any help is appreciated.

The codes below are snippets of my original program to make it less wordy.

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>
4

1 回答 1

1

看来你错过了"="

response.sendRedirect("Testrec.jsp?ed="+ed);
于 2013-05-15T12:41:20.270 回答