mderbin
asked on
Need variables to carry over to another included page
About half way down a JSP, I have an include statement like this:
<jsp:include page="page2b.jsp" flush="true"/>
page2b.jsp then uses some logic that evaluates some variables from the first page.
Is there a way that I can declare and set the variables on the first page in a way that they can be read on page2.jsp?
I imagine that there are session varibales (although I am not sure how to declare them).
But is there another way that I can include the page2.jsp so that it will be read by the server as a part of the first page an accept the variables as though they were set on that page?
<jsp:include page="page2b.jsp" flush="true"/>
page2b.jsp then uses some logic that evaluates some variables from the first page.
Is there a way that I can declare and set the variables on the first page in a way that they can be read on page2.jsp?
I imagine that there are session varibales (although I am not sure how to declare them).
But is there another way that I can include the page2.jsp so that it will be read by the server as a part of the first page an accept the variables as though they were set on that page?
you need to use
<%@ include file="page2b.jsp" %>
That way the file gets included at translation phase
<%@ include file="page2b.jsp" %>
That way the file gets included at translation phase
ASKER
I tried that, but the value of the variable is still coming up null all of the time on page2b.jsp.
So now my page2.jsp looks like:
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d river.*,ja va.io.*" %>
<%@ page import="com.oreilly.servle t.Multipar tRequest"% >
<%
String $link = request.getParameter("link ");
if($link.equals("1")){
MultipartRequest multi = new MultipartRequest(request," d:/WebSphe re/AppServ er/install edApps/glo balis.ear/ globalis.w ar/META-IN F/uploads/ images", 50 * 1024, new com.oreilly.servlet.multip art.Defaul tFileRenam ePolicy()) ;
out.println("<br><b>Parame ters</b><b r>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()) {
String $parm_name = (String)params.nextElement ();
String $parm_value = multi.getParameter($parm_n ame);
if($parm_value == null || $parm_value.equals("")){ $parm_value = ""; }
out.println("<br>"+$parm_n ame + " = " + $parm_value);
if($parm_name.equals("name 2")){
String $name2 = $parm_value;
}
}
}else{
String $through = request.getParameter("thro ugh");
out.println("<br>through=" +$through) ;
out.println("<br>link="+$l ink);
}
%>
<%@ include file="page2b.jsp" %>
And page2b.jsp looks like this:
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d river.*,ja va.io.*" %>
<%@ page import="com.oreilly.servle t.Multipar tRequest"% >
<%
String $name2 = request.getParameter("name 2");
out.println("<br>The text in name2="+$name2);
out.println("<br><br><a href=page2.jsp?link=1&thro ugh=michae l>page2 click here</a>");
out.println("<br><a href=page1.jsp>page1 click here</a>");
%>
And the results on the web look like this:
Parameters
Submit = Submit
link = 1
name2 = kmkmkmkm
The text in name2=null
page2 click here
page1 click here
Do I need to do something on page2b.jsp to get the variable from page2.jsp (right now I am using String $name2 = request.getParameter("name 2");)?
Thanks,
-MD
So now my page2.jsp looks like:
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d
<%@ page import="com.oreilly.servle
<%
String $link = request.getParameter("link
if($link.equals("1")){
MultipartRequest multi = new MultipartRequest(request,"
out.println("<br><b>Parame
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements())
String $parm_name = (String)params.nextElement
String $parm_value = multi.getParameter($parm_n
if($parm_value == null || $parm_value.equals("")){ $parm_value = ""; }
out.println("<br>"+$parm_n
if($parm_name.equals("name
String $name2 = $parm_value;
}
}
}else{
String $through = request.getParameter("thro
out.println("<br>through="
out.println("<br>link="+$l
}
%>
<%@ include file="page2b.jsp" %>
And page2b.jsp looks like this:
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d
<%@ page import="com.oreilly.servle
<%
String $name2 = request.getParameter("name
out.println("<br>The text in name2="+$name2);
out.println("<br><br><a href=page2.jsp?link=1&thro
out.println("<br><a href=page1.jsp>page1 click here</a>");
%>
And the results on the web look like this:
Parameters
Submit = Submit
link = 1
name2 = kmkmkmkm
The text in name2=null
page2 click here
page1 click here
Do I need to do something on page2b.jsp to get the variable from page2.jsp (right now I am using String $name2 = request.getParameter("name
Thanks,
-MD
>using String $name2 = request.getParameter("name 2");
You could just remove that line from page2b.jsp .
The variable will be seen in a <%@ include .
You could just remove that line from page2b.jsp .
The variable will be seen in a <%@ include .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked - thanks - now I just have to get the code from this simple test environment to the REAL code.
This project is going to be the death of me...
Thanks again.
This project is going to be the death of me...
Thanks again.
ASKER
I have the following page(page1.jsp):
*************** page1.jsp *********************
<html>
<head>
<title>Page1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="page2.jsp?link=1" method="post" name="form1" enctype="multipart/form-da
<input name="name2" type="text" size="25" maxlength="25"><br>
<input type="file" name="uploadfilename" > <br>
<input type="reset" value="Reset" name="Reset">
<input type="submit" value="Submit" name="Submit">
</form>
</body>
</html>
***************end of page1.jsp *******************
This form calls page2.jsp, which uses oReilly.servlet to get the form data:
****************** page2.jsp *********************
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d
<%@ page import="com.oreilly.servle
<%
String $link = request.getParameter("link
if($link.equals("1")){
MultipartRequest multi = new MultipartRequest(request,"
out.println("<br><b>Parame
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements())
String $parm_name = (String)params.nextElement
String $parm_value = multi.getParameter($parm_n
if($parm_value == null || $parm_value.equals("")){ $parm_value = ""; }
out.println("<br>"+$parm_n
if($parm_name.equals("name
String $name2 = $parm_value;
}
}
}else{
String $through = request.getParameter("thro
out.println("<br>through="
out.println("<br>link="+$l
}
%>
<% String $myzone = "page2b.jsp"; %>
<jsp:include page="<%=$myzone%>" flush="true"/>
***************end of page2.jsp *******************
The bottom of page2.jsp calls the simple include page2b.jsp, which I want to print to the screen the variable "name2"
***************end of page1.jsp *******************
<%@ page import="java.sql.*, java.util.*, oracle.sql.*,oracle.jdbc.d
<%@ page import="com.oreilly.servle
<%
String $name2 = request.getParameter("name
out.println("<br>The text in name2="+$name2);
out.println("<br><br><a href=page2.jsp?link=1&thro
out.println("<br><a href=page1.jsp>page1 click here</a>");
%>
***************end of page2b.jsp *******************
But "name2" always comes out null.
I cannot use oReilly.servlet to read in the parts of the form again in page2b.jsp (it always fails - probably because page2.jsp is not a form).
How can I get page2b.jsp to recognize "name2" and print the value to the screen that i type into page1.jsp?
Thanks,
-MD