Javascript  
 
  ScriptJava  
 
  Perl  
 
  PHP  
 
  ROR  
 
  ask us  
 

 

Applications
  1. Getting started
  2. Definitions
  3. First program
  4. Characters and Strings
  5. Object and methods
  6. Arrays and Circles
  7. Exceptions
  8. The main method
  9. Reading
  10. Writing file
  11. Vectors
  12. Stacks
  13. Map The Dictionary
  14. Lists
  15. Linked lists
  16. Collection
  17. Interfaces
  18. Scanner
  19. StringTokenizer
  20. Generics
  21. JDBC
  22. DataBase Queries
  23. JSP, The main step

Graphics

Applets
  1. Regards
  2. One Picture
  3. Calculator
  4. Random pictures
  5. Bouncing picture

Swings
  1. Buttons listeners
  2. TextFields
  3. Swing Example

JavaBeans
  1. The first step
  2. Example

Search a word:
   



© The scientific sentence. 2010

Java beans and JSP first step
JavaBeans, the first step


The idea of beans is to have some Java programs (beans) 
available to use for any other applications. For example, 
a program TheSimpleBean.java, once compiled, its 
corresponding TheSimpleBean.class file will be used 
by any other application. In java, to set this little 
related program (bean), this bean must be serializable, 
has an empty constructor, and has getter and 
setter methods (the properties); like this:

public class TheSimpleBean implements java.io.Serializable {

package NestDirectory;

private Type PropertyName;

public TheSimpleBean () {}

public Type getPropertyName() {
return PropertyName;
}

public void setThePropertyName(Type ThisPropertyName) {
PropertyName = ThisPropertyName;
}
}

The class implements the interface Serializable class. This class has no methods;
It allows just the object to be stored and then retrieved some later time. In order to 
locate the bean, we mention at first its nest directory as a package. This directory 
is a subdirectory of /WEB-INF/classes/, rekated to Tomcat. That is the file 
TheSimpleBean.java is located at : /WEB-INF/classes/NestDirectory/. 
If there are other subclasses X1, X2, ...Xn between /WEB-INF/classes/, for example: 
/WEB-INF/classes/X1/X2/X3/NestDirectory/, we mention the package as follows:

package X1.X2.X3.NestDirectory;

Now, we will use this JavaBean in JSP program. More precisely, JSP will call 
TheSimpleBean.class by the following tags properties:

<jsp:useBean 
ID = "Object Name" 
class="Package/NameOfClass" 
/>
<jsp:setProperty  
name ="ID Of JavaBean, ie Object Name" 
property = "PropertyName" 
value="New value of this Property"
/>
<jsp:getProperty 
name = "ID Of JavaBean, ie Object Name" 
property="PropertyName"
/>

We built TheSimpleBean.jsp like this:
<html>
<head>
<title> TheSimpleBean JSP Page</title>
</head>
<body>

<jsp:useBean id = "ObjectName" class = "X.NestDirectory.TheSimpleBean">
<jsp:setProperty name = "ObjectName" property="PropertyName" 
value="The value of the PropertyName" />
</jsp:useBean>
 
<jsp:getProperty name="ObjectName" property = "PropertyName"/>

</body>
</html>

And place it in the in /WEB-APP folder.


  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.