Js
One of the attractions of JSP Web pages is the ability to combine JavaBean technology to expand the functionality of programs in a Web page. JavaBean is a Java class (class) that encapsulates properties and methods to become an object that has some functionality or that deals with a business. JavaBean is organized into package (packets) for management, in effect, is to put a group of JavaBean together in a certain directory, the definition of each class plus package So-and-So, in this case, test. Directory test must be placed in the directory contained in the system environment classpath, the system can find the JavaBean. JSWDK adds Jswdk-1.0.1webpagesweb-infjspeans to Classpath in default state. It is also an easy way to set up your own JavaBean and package in this directory.
A simple JavaBean framework is described below. Create a text file Helloworld.java with a text editor and save it in the Jswdk-1.0.1webpagesweb-infjspeans est directory, which reads as follows:
Package test;
public class HelloWorld {
Public String name = ' My name ';
Public String Gethi ()
{
Return "Hello from" + name;
}
}
Helloworld.java edited, in DOS, into the directory Jswdk-1.0.1webpagesweb-infjspeans, with JDK javac command compiled Helloworld.java as follows:
Javac Helloworld.java
Note that Java is case-sensitive, and in a program, the letters in the compilation command line cannot be written in a wrong case. The success of compilation means that a JavaBean is established. Here's how to use this JavaBean in a JSP. Create a text file hi-bean.jsp with a text editor and save it in the Jswdk-1.0.1webpages est directory, which reads as follows:
-------------------------------------------------------------
In a JSP Web page, use syntax to create a JavaBean object and name it Hellobean. The reader can see from this simple example the setting, getting the JavaBean property, and invoking the JavaBean method. Type http://localhost:8080/test/hi-bean.jsp in the address bar of the browser, and get the results as shown in Figure 3. Note that if you modify and recompile the JavaBean program, the results of the modified Web server that need to shut down and restart the JSWDK will not be effective. If you only modify the JSP file, you do not have to restart the JSWDK Web server.
Although, this only completes a very simple JavaBean framework, but follow this framework can design a variety of javabean. For example, accessing data from a JSP is usually done through JavaBean.