HTML JSTL SQL TAGS: passing session variable values between pages

Hello I have multiple JSP pages implementing a contact type database. I am passing data from one page to the next using html input variables. It works from the first jsp to the second apparently. But after that it does not work anymore. The name and number variables (param.name) no longer are accessible in the fourth jsp, or it atleast appears that way, because the code in the fourth jsp is not returning the value. Below I have the four jsp. Tell me if it is my code or am I missing something? I want to make the input variables available on all jsp.

jsp 1:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <sql:setDataSource var="data" driver="org.apache.derby.jdbc.ClientDriver"
     url="jdbc:derby://localhost:1527/testing"
     user="testing"  password="testing"/>
    </head>
    <form action="result.jsp"> 
     Enter name:
    <input type="text" name="name" scope='session'>

    Enter Number
    <input type="text" name="number" scope='session'>
    <input type="submit" value="Search Rolodex" name="submit" />
    </form>

        <br></br>



    <form name="add" action="addData.jsp">
        <input type="submit" value="Add Contact" name="addc" />
    </form>
    <body>

jsp 2:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <sql:setDataSource var="data" driver="org.apache.derby.jdbc.ClientDriver"
     url="jdbc:derby://localhost:1527/testing"
     user="testing"  password="testing"/>
    </head>

    <body>
        <form name="editp" action="editData.jsp">

        <sql:query var="result" dataSource="${data}">
            SELECT NAME, NUMBER FROM DATA WHERE NAME = '${param.name}' OR NUMBER = '${param.number}'
        </sql:query>

        <table border="1">
            <!-- column headers -->
            <tr>
                <c:forEach var="columnName" items="${result.columnNames}">
                    <th><c:out value="${columnName}"/></th>
                    </c:forEach>
            </tr>
            <!-- column data -->
            <c:forEach var="row" items="${result.rowsByIndex}">
                <tr>
                    <c:forEach var="column" items="${row}">
                        <td><c:out value="${column}"/></td>
                    </c:forEach>
                </tr>
            </c:forEach>
        </table>


                <input type="submit" value="Edit Contact" name="edib" />
            </form>









    </body>
</html>

jsp 3:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <sql:setDataSource var="data" driver="org.apache.derby.jdbc.ClientDriver"
     url="jdbc:derby://localhost:1527/testing"
     user="testing"  password="testing"/>

    </head>
    <body>
       <form name="editred" action="editRedirect.jsp">


    <input type="text" name="newname" scope='session'>
    <input type="text" name="newnumber" scope='session'>

    <input type="submit" value="Close" name="close" />   
        </form>   
    </body>

</html>

jsp 4

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <sql:setDataSource var="data" driver="org.apache.derby.jdbc.ClientDriver"
                           url="jdbc:derby://localhost:1527/testing"
                           user="testing"  password="testing"/>
    </head>
    <body>

        <form name="sendhome" action="index.jsp">


        <sql:update var="updatevariable" dataSource="${data}">
            UPDATE DATA
            SET NAME = '${param.newname}'
            WHERE NAME = '${param.name}'
        </sql:update> 
        <sql:update var="updatevariable2" dataSource="${data}">
            UPDATE DATA
            SET NUMBER = '${param.newnumber}'
            WHERE NUMBER = '${param.number}'
        </sql:update>  
            <input type="submit" value="Home" name="returnhome" />  
</form>
    </body>

</html>


Source: jsp

Leave a Reply