0

So, I'm using two jsps: test1.jsp and test2.jsp. I'm importing the second in the first using c:import. I'm able to pass in a value to test2 using c:param. How do I a) use this value as a variable in test2 and b) pass back a variable to test1? Some example code would be greatly appreciated.

Thanks

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by martin5211
0

You could use a non-enterprise JavaBean, then use <jsp:setProperty> and <jsp:getProperty>

Edited by martin5211: n/a

0

Code for JavaBean:

package com.example;

public class Person {
	public String name;
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		return this.name;
	}

}

result.jsp

<jsp:useBean id="person" type="com.example.Person" class="com.example.Person" scope="session">
  <jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>
Person: <jsp:getProperty property="name" name="person"/>

result2.jsp

<jsp:useBean id="person" type="com.example.Person" class="com.example.Person" scope="session">
</jsp:useBean>
Person: <jsp:getProperty property="name" name="person"/>

Don't forget to use session scope for your javabeans.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.