When writing JSP Dynamic Web design, how to apply JavaBean? Below I explain step-by-step, explain, this is only my experience, may not be completely summed up, of course I have successfully compiled and used correctly.
(the diagram below)
JavaBean. Class byte files can be placed in the classes directory of Tomcat itself, but it is best to customize the directory to create the following directory in the current directory: .../web-inf/classes (for example, I used webapps/example/. Web-inf/classes/. In the illustration above, the Hello.java used in the example that I cited, which has been compiled, generated hello.class byte files and placed in the Classes folder, is not like the position of the JavaBean that makes any other Web service file available, directly Put the. class byte file into the classes directory that you already have in Tomcat. But now that the high version of Tomcat does not have these directories, then the application JavaBean, of course, to build these directories themselves.
When creating a directory, note that the folder name is Web-inf, not wen_inf, note that the middle of the bar to write the right; the folder name is classes and not the name of the package under Class;classes also note that it is the same as the package name in your JavaBean, for example, You have the following statement in the JavaBean file: Import Bao means that you have introduced a package named Bao, then the package name (folder name) under the Classes folder should be Bao.
Then write a good javabean, compile. Here to say how to compile JavaBean in DOS: Start-run-enter cmd--via CD. or the CD into the JavaBean directory (such as the image of the Hello.java file, I put it in the Mypao, then in DOS, it is necessary to enter the directory to compile it), and then enter the command: Javac After Hello.java, you can get the Hello.class byte file generated in the Mypao package and compile it. If the JavaBean has been modified, remove the old. class file first and recompile the JavaBean.
You can then use it in your JSP. I'm copying the code to explain it, a1.jsp file code is as follows:
﹤%@ page contentType="text/html;charset=GB2312" %﹥
﹤%@ page import="mypao.Hello"%﹥
﹤!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"﹥
﹤html xmlns="http://www.w3.org/1999/xhtml"﹥
﹤head﹥
﹤meta http-equiv="Content-Type" content="text/html; charset=gb2312" /﹥
﹤title﹥JavaBean的应用﹤/title﹥
﹤/head﹥
﹤body bgcolor="#9900FF"﹥
﹤center﹥
﹤p﹥﹤h3﹥下面用JavaBean显示:﹤/h3﹥﹤/p﹥
﹤jsp:useBean id="hh" class="mypao.Hello" scope="page"﹥ ﹤/jsp:useBean﹥
﹤%=hh.getX()%﹥
﹤/body﹥
﹤/html﹥