建立自己的JavaBean
添加两个文件:
1. ..\myapps\WEB-INF\classes\test\TestBean.java:
package test; public class TestBean { private String name = null; public TestBean(String name) { this.name = name; } public void setName(String name){ this.name = name; } public String getName() { return this.name; } }
2. ..\myapps\testBean.jsp:
<%@ page import="test.TestBean" %> <html> <head> <title>Test Bean</title> </head> <body> <center> <% TestBean bDemo = new TestBean("My First Java Bean"); %> Java Bean: Print By server: <%=bDemo.getName()%> </center> </body> </html>
3. 重启Tomcat, 并输入到地址栏:http://localhost:8080/myapps/testBean.jsp 页面打出"My First Java Bean",大功告成!
路慢慢其休远羲,吾将上下而求所