Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pass params from jsp to another jsp help

 
Zoe Peng
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Zoe Peng
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]);
}
...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic