• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object instance solved, but...

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like I said before:

In a jsp page i have the source code bellow:
if(request.getParameter("obj")==null)
{solti = new YYY.SolicitacaoTI(); }
With this object i full fill some fields of this page. In the first try, everything ok. But when i visit this page for the second time, the fields have the same information off the last time. Therefore, a new instance of this object it�s not created...why?
PS:
<jsp:useBean class="YYY.SolicitacaoTI" id="solti" scope="session"/>
However, i think that�s not the problem because i have another jsp page with the same procedury but with a diferente scope (request) and the same problem it�s happening....
What�s wrong?
PS2: Tomcat 5.0

Ok, I�ve got the idea with the session scope, but now i need to kill the session tho clean up the page fields... I used first session.removeAttribute("object") and session.invalidate(), but when i visit the page for the second time, all the fields wasn�t in blank.... I think the object wasn�t removed.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!

I think the problem is with your jsp:usebean as the scope in this case is session, When you first visit the page a variable with name solti is looked into the session if available it will be reused or else a new one is created in the session scope... so the first time as the object is not available this variable is created. the second time when you come to this page as you are in the same session the object would still be present in the session and thus the same object will be used instead of the creating a new object. And for some reason the request parameter obj is not being null and so it would not reinitialize the object with a new location. But by doing new everytime youare coming to the page, specially the variable being the one in the session scope i thnk you are creating memory leasks also.. ofcourse this is a different thing all together.
So, check to see if you are even getting into the if block. use a print statement.
coming to other point where u said the scope was request ....that it self says that the your object is valid only for that request and so you might not be seing any issue.
 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murthy Cherukumilli:
hi!

I think the problem is with your jsp:usebean as the scope in this case is session, When you first visit the page a variable with name solti is looked into the session if available it will be reused or else a new one is created in the session scope... so the first time as the object is not available this variable is created. the second time when you come to this page as you are in the same session the object would still be present in the session and thus the same object will be used instead of the creating a new object. And for some reason the request parameter obj is not being null and so it would not reinitialize the object with a new location. But by doing new everytime youare coming to the page, specially the variable being the one in the session scope i thnk you are creating memory leasks also.. ofcourse this is a different thing all together.
So, check to see if you are even getting into the if block. use a print statement.
coming to other point where u said the scope was request ....that it self says that the your object is valid only for that request and so you might not be seing any issue.




And the session.removeAttribute("solti"), session.invalidate()... these method�s that i use on my "logoff page" should work, shouldn�t?....
My source code:

if(session.getAttribute("solti")==null)
{ solti = new YYY.SolicitacaoTI(); }
try{
if(quem.equals("1"))
{
dep = request.getParameter("dep");
nom = request.getParameter("nom");
if(!nom.equals("null"))
{
if(!nom.equals(""))
{
solicitacao = session.getAttribute("solti");
classe = solicitacao.getClass();
metodo = classe.getMethods()[getMetodo(classe.getMethods(),1)];
args[0] = new String(nom);
metodo.invoke(solicitacao,args);

// old values come back from here, the old object reference (i dont think that�s a cache problem....)

centroc = classe.getField("centrocusto").get(solicitacao).toString();
tel = classe.getField("telefone").get(solicitacao).toString();
loc = classe.getField("local").get(solicitacao).toString();
locf = classe.getField("localf").get(solicitacao).toString();
ee = classe.getField("endeletronico").get(solicitacao).toString();
}
}

the page that�s finish the user�s operation has

Object solicitacao = session.getAttribute("solti");
Class classe =solicitacao.getClass();
Method metodo = classe.getMethods()[getMetodo(classe.getMethods())];
Object[] args = new Object[]{request.getParameter("txtaDesc"), request.getParameter("selTipo"), request.getParameter("selOrigem"), request.getParameter("textData"), request.getParameter("showTime")};

metodo.invoke(solicitacao,args);
session.removeAttribute("solti");
session.invalidate();

Thank�s again,
Rafael.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your first code snippet, how is the solti variable defined? If it's defined using <%!...%> it acts like a class level variable. Is the "obj" request parameter ever being set? It would help to see more of the JSP code for your page...
 
Murthy Cherukumilli
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes they should unless you have some kind of exception in your reflection code.
 
Rafael Fagundes
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murthy Cherukumilli:
yes they should unless you have some kind of exception in your reflection code.



The problem is that no exception occur when a�m using the system...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic