Hello Hello, As you can see, using a

<%@ import = HelloBean %> Hello

Hello, <%= hello.getName() %>

As you can see, using a JavaBeans component with JavaServer Pages greatly reduces the amount of code necessary in the page. This allows a clean separation of content (the functionality the bean provides) from presentation (the HTML structure of the page). By using a well-defined API to interact with the bean, even nonprogrammers can write JSP pages. The code for HelloBeanis shown in Example 2-12. Its class file should be placed in the server’s classpath (something like server_root/classes, although for the Java Web Server you need to first create this directory). Example 2-12. The HelloBean class public class HelloBean { private String name = World ; public void setName(String name) { this.name = name; } public String getName() { return name; } } This is about as simple a bean as you’ll ever see. It has a single nameproperty that is set using setName() and retrieved using getName(). The default value of nameis “World”, but when a request comes in that includes a NAMEparameter, the property is set automatically by the server with a call to setName(). To test the mechanism, try browsing to http://server:port/hellobean.jsp. You should see something similar to the screen shot in Figure 2-13.
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services

Comments are closed.