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>

1 Answer 1

1

It looks that you missed "="

response.sendRedirect("Testrec.jsp?ed="+ed);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Damn just missed a punctuation mark and it caused me so much headache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.