tomcat+bean例子

时间:2021-08-02 03:17:30

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app\WEB-INF\classes\文件夹下

建立beanTestPackage文件夹

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app\WEB-INF\classes\beanTestPackage文件夹下

建立文件BeanTest.java,内容如下

package beanTestPackage;

public class BeanTest
{
private String text; public BeanTest(String inputText){
this.text = inputText;
} public void setText(String newText){
this.text = newText;
} public String getText(){
return this.text;
} }

命令行执行

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app\WEB-INF\class

es\beanTestPackage>javac BeanTest.java

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app文件夹下

建立testBean.jsp内容如下

<%@ page import="beanTestPackage.BeanTest" %>

<%
BeanTest testBean = new BeanTest("I want to learn something about java, in order to tree new bee!");
%> <%=testBean.getText()%>

访问http://127.0.0.1:8080/app/testBean.jsp即可得结果。