日期:2014-05-16 浏览次数:20370 次
package std;? import java.io.*;? ????? public class StandardBean implements Serializable {? ??? private String user = null;? ??? private String city = null;? ????????? ??? //the none method? ??? public void StandardBean() {? ??? }? ??? public String getUser() {? ??????? return user;? ??? }? ??? public void setUser(String user) {? ??????? this.user = user;? ??? }? ??? public String getCity() {? ??????? return city;? ??? }? ??? public void setCity(String city) {? ??????? this.city = city;? ??? }? }?
?
<%@ page contentType="text/html" pageEncoding="GBK"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>JSP Beans Page</title> <jsp:useBean id="lin" class = "std.StandardBean"/> <jsp:setProperty name="lin" property="user" value="林"/> <jsp:setProperty name="lin" property="city" value="烟台"/> </head> <body> <% out.print(lin.getUser()); out.print(lin.getCity()); %> </body> </html>
?
?
部署环境为Apache Tomcat/6.0.32
具体目录为
webapps/bean/WEB-INF/classes/std下有StandardBean.class
webapps/bean/WEB-INF/src/std下有StandardBean.java?
webapps/bean/StandardBean.jsp
访问的地址为:http://localhost:8080/bean/StandardBean.jsp?
?
注意:当编码格式为UTF-8时无法显示汉字,但是当编码格式为GBK或者GB2312时都可以正常显示。