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

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.