aspose file tools*
The moose likes Servlets and the fly likes pass params from jsp to another jsp help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "pass params from jsp to another jsp help" Watch "pass params from jsp to another jsp help" New topic
Author

pass params from jsp to another jsp help

Zoe Peng
Ranch Hand

Joined: Nov 27, 2000
Posts: 112
I try to pass three param from file1 to file2.
but, file2.jsp just can't get these parameters.
what's wrong??
Thanks.
//file1.jsp
<jsp:include page = "./file2.jsp" flush="true" >
<jsp aram name = "param1" value="value1" />
<jsp aram name = "param2" value="value2" />
<jsp aram name = "param3" value="value3" />
</jsp:include>
//file2.jsp(not working)
String[] s =
{
"param1" , "request.getParameters(param1)",
"param2", "request.getParameters(param2)",
"param3", "request.getParameters(param3)"
};
another way..file2.jsp(still not working)
String[] s = request.getParameterValues("s[]");
it works when I just give file2 default values
String[] s =
{
"param1" , "value1",
"param2", "value2",
"param3", "value3"
};
Jayson Falkner
Author
Ranch Hand

Joined: May 07, 2001
Posts: 57
The problem lies in placing quotes around your code statements.
Here is an example:
// Makes a String that says 'request.getParameter(param1)'
String param1 = "request.getParameter(param1)";
However if you take those quotes off:
// Makes param1 the returned String from request.getParameter()
String param1 = request.getParameter("param1");
Here is your code slightly changed to work
//file1.jsp
<jsp:include page = "./file1.jsp" flush="true" >
<jsp:param name = "param1" value="value1" />
<jsp:param name = "param2" value="value2" />
<jsp:param name = "param3" value="value3" />
</jsp:include>
//file2.jsp
<%
String[] s =
{
request.getParameter("param1"),
request.getParameter("param2"),
request.getParameter("param3")
};
%>
<%= s[0] %><br/>
<%= s[1] %><br/>
<%= s[2] %>
Jayson Falkner
V.P./CTO, Amberjack Software LLC
Jayson@jspinsider.com
www.jspinsider.com


Jayson Falkner<br />jayson@jspinsider.com<br />Author of <a href="http://www.jspbook.com" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
Zoe Peng
Ranch Hand

Joined: Nov 27, 2000
Posts: 112
Hello Jayson,
Thx. I figure out what to do now.
one my file2.jsp, I need to pass these three parameters(I get from file1.jsp) to another server again after I open URLConnection. Everhing is working now..Thank again.
//files2.jsp
String[] s =
{
"param1", request.getParameter("param1"),
"param2", request.getParameter("param2"),
"param3", request.getParameter("param3")
};

for (int i = 0; i < s.length; i++)
{
s[i] = URLEncoder.encode(s[i]);
}
StringBuffer sb = new StringBuffer();
sb.append(s[0]).append("=").append(s[1]);
for (int i = 2; i < s.length-1; i += 2)
{
sb.append("&").append(s[i]).append("=").append(s[i+1]);
}
...
 
jQuery in Action, 2nd edition
 
subject: pass params from jsp to another jsp help