Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About the javabean properties problem?  RSS feed

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone:
I am a new learner.I have a problem with the properties of javabean.For example:we can see this usually in a javabean or servlet : "String name=null; void setname(String name){this.name=name;} String getname(){return this.name " How it does?And how I can use it?There is any advantage using it in jsp?I don't understand its function really!Can anyone can help me?Thank you! :roll:
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
This sort of code constitutes a component called bean which is usually used in JSP pages for storing values captured from HTML forms & store the values in session & subsequently storing the data in DB. The bean has methods mapped to the form input fields.
Search in the Google using the kwords form,bean,JSP
 
Joe Broderick
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to declare your bean in your jsp code. then you can use any methods in your beans in your jsp pages. i do not remember the exact code, but it looks something like < id = "someId" class = "nameOfClassToBeUsed" >. i know i am missing something in there. the way you would use the method in the class is by calling the id, for exammple, if i wrote someId.getName(), it would use the method getName from the nameOfClassToBeUsed class. I hope that helps a bit.
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe Broderick and sureshg:
Thank your reply.I have a test.But it failed.Must a javabean have unique property?
My javabean is:
//////////////////////finalpro.finalpro/////////
package finalpro;
public class finalpro{
String te=null;
String Id=null;
public void sette(String te){
this.te=te;
}
public String gette(){
return this.te;
}
public void setId(String Id){
this.Id=Id;
}
public String getId(){
return this.Id;
}
}
/////////////////////////////////////////////
I use it in my jsp //////////////////////////
<%@ page contentType="text/html; charset=gb2312" %>
<jsp:useBean id="li" class="finalpro.finalpro" scope="page" />
<html>
<body>
<jsp:setProperty name="li" property="te" value="qijiashe" />
method1:<p>
code:<jsp:getProperty name="li" property="te" />
<hr>
method2<p>
<jsp:setProperty name="li" property="Id" value="hello" />
code:<jsp:getProperty name="li" property="Id" />
</body>
</html>
/////////////////////////////////////
But it can't work property!Tomcat4 says:"Cannot find any information on property 'Id' in a bean of type 'finalpro.finalpro'
" But I have the Id property certainly. :roll:
It works well if I delete the "<jsp:setProperty name="li" property="Id" value="hello" />
<jsp:getProperty name="li" property="Id" />" code.Why?
 
Sarthishari Kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yahnoo lyo..
The problem is with the naming of the variables in the Bean.
Assume u have a property called 'name' in the Bean.
String name = null;
The corresponding get and Set methods should be
setName(..)
getName()
The first letter of the name of the property should be in Caps in the get and set Methods.
Revert back if this doesn't work...
Sathish
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
the code is correct & there is no peoblem. one thing u have to do is put the finalpro javabean claass inside a folder named finalpro under web-inf/classes
so tthe class must be in web-inf/classes/finalpro/finalpro.class
when I run the program under weblogic the output came correctly
method1:
code:qijiashe

--------------------------------------------------------------------------------
method2
code:hello
the thing is u have to maintain the package structure under the classes dir
hope this helps
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends:
The test is successful after I change it to setName and getName under Tomcat.But it can be successfull under weblogic as sureshg says.Mybe the container is different result of this.Thank you very much.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!