• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple question for u

 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
how do i get a property in bean(in jsp) which requires to pass
a parameter also?

Thankx..
bhupendra
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a .java file to be a properly written Java Bean, for 'prop1' property there should be 'public String getProp1() {}' and 'public void setProp1() {}' methods.
I am not sure if I understand your question correct. In a .jsp file to get the propertly value,

This method will grab the property named 'password'. If you would like to pass conditional parameters , write anoter method which takes your parameter , analyzes , in turn calls one of get***() methods and returns as String value.
regds
maha anna
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only reason that I would use <% %> instead of <%! %> for workerBean is that the last one creates a member variable of the class, while the first one generates a local variable for the _jspService() method. That's in case there would be some threading issues. I do it as a rule of thumb...
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
Since my workerbean's life starts and dies within 'request' scope I choose to do this way. The point which you brought to notice is also very important.
regds
maha anna
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, your question is simple but the most frequently asked.The properties of beans worked out with jsp can easily be contolled by the usebean tag and then accessing it via getproperty-setproperty parameters.This is very simple but the most favoured way of setting a jsp-bean.
<%usebean id=???%
<%set property=???%>
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a simple doubt.Before using "workerBean.getPassword()" is it not necessary to get the "LoginWB " from the session context. How can you refer "LoginWB" once you make it "null". I always have simple doubts... pl.clear me....
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sasi,
Yes. Your doubt is very much valid one. When a ref is set to null we can't invoke any method on it. At runtime we will get 'NullPointerException'.
The above jsp file will work fine without any 'NullPointerException' even if we don't get the LOginWB object from request/session scope, the reason being, "The servlet/jsp engine will call the bean's no-argument contructor and will create an object ,in case if it doesn't find an already existing request/session scoped object which is used in <%usebean... tag's scope attribute. This is the servlet 2.2 and jsp 1.1 specification.
This means we have to write our bean .java files to be a PROPER bean which obeys the rules to be a proper JavaBean. One of the rules is it must have a no-argument contructor.
In case if the servlet engine is not able to find the no-arg contructor, at runtime we will get some errors thrown at the browser, saying "Unable to fine no-arg constructor" , something simillar, not "NullPointerException"
My LoginWB bean does have a no-arg constructor, so even if the user directly types http://localhost/MISApp/login.jsp, we will not get "NullPointerException' or "Unable to find no-arg constructior" runtime errors thrown at browser.
regds
maha anna

[This message has been edited by maha anna (edited March 28, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic