Dave Hathaway

Greenhorn
+ Follow
since Dec 11, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dave Hathaway

I finally worked it out - to make the object visible to the bean setAttribute afterwards.
For Example:
<%@ page import="CounterBean" %>
<jsp:useBean id="counter" class="CounterBean" scope ="request" >
<% counter = new CounterBean();
counter.setCount(44);
request.setAttribute("counter",counter); %>
<h3>
the count should be 44 but is?
<jsp:getProperty name="counter" property="count" />
</h3>
</jsp:useBean>
23 years ago
Sowmya - thanks for the reply.
This will work but doesn't answer the question why can't I change the object reference of counter?
Sometimes I made need to change the object reference - if I wanted to say receive a counter from a vector of counters (list) which had been set by a servlet (setAttribute("list",list) - how I could I access this with getProperty.
I am getting the same problem having changed the object reference.
In this case...
<%@ page import="CounterBean" %>
<jsp:useBean id="counter" class="CounterBean" / >
<%
Vector v = (Vector)request.getAttribute("list");
Iterator i = v.iterator();
while (i.hasNext()){
counter = (CounterBean)i.next();
counter.setCount(44);
<h3>
the count should be 44 but is?
<jsp:getProperty name="counter" property="count" />
</h3>
<% } %>

23 years ago
I am trying to use an object with getProperty, the object is created within a scriplet. I am not getting the object created in the scriplet - can anyone please let me know why?
here is the Server Page
<%@ page import="CounterBean" %>
<jsp:useBean id="counter" class="CounterBean" >
<% counter = new CounterBean();
counter.setCount(44);
System.out.println("counter count:" + counter.getCount());%>
</jsp:useBean>
<h3>
the count should be 44 but is?
<jsp:getProperty name="counter" property="count" />
</h3>
and here is my CounterBean
public class CounterBean
{
private int count;
public int getCount()
{
return count;
}

public void setCount(int count)
{
this.count=count;
}
}
When running the JSP I get the following output
the count should be 44 but is? 0
I expect the count to be 44.
23 years ago
Hello,
If a local variable, say String, is set to null in a method but this String is also returned from this method at which point is this variable eligable for Garbage Collection?
Is it after the String has been set to null or after the method call has ended?
The method would look like this
public String anymethod()
{
String s = new String("XXXXXXXXX");
s = null;
return s;
}
I am confused as to whether eligibility for GC is after being set to null or after it is no longer used.