jsp调用javabean实例
goodsbean.java
package sale;
public class goodsbean{
String Product;
double Price;
public goodsbean (){
this.Product = "box";
this.Price = 5.0;
}
public void setProduct (String ProductName){
this.Product = ProductName;
}
public String getProduct(){
return (this.Product);
}
public void setPrice (double priceValue){
this.Price = priceValue;
}
public double getPrice(){
return (this.Price);
}
}
编译完生成的.class文件,放到:Tomcat 5.5\webapps\ROOT\WEB-INF\classes\sale 目录下。
调用方法:
<%@ page contentType="text/html;charset=GB2312"%>
<%//request.setCharacterEncoding("iso_8859_1");%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>goodsbean</title>
</head>
<body>
<jsp:useBean id="goodsbean" scope="application" class="sale.goodsbean" />
<%
goodsbean.setProduct("clock");
goodsbean.setPrice(17);
%>
使用方法1:
产品:<%= goodsbean.getProduct()%><br>
税率:<%= goodsbean.getPrice()%>
<%goodsbean.setProduct("chair");
goodsbean.setPrice(3);
%>
<br>使用方法2:
产品:<jsp:getProperty name="goodsbean" property = "Product" />
<br>
税率:<jsp:getProperty name="goodsbean" property = "Price" />
</body>
</html>
注意:设置bean的属性如下
<jsp:setProperty name="goodsbean" property = "Product" value="asdf"/>
<jsp:setProperty name="goodsbean" property = "Price" value="adad" />
相关文档:
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%>< ......
1 javascript ,设置一个变量,只允许提交一次。
2 还是javascript,将提交按钮或者image置为disable
onsubmit="getElById('submitInput').disabled = true; return true;">
3 利用struts的同步令牌机制
......
JSP页面中一般有两类注释
1.html注释
形如<!--...................-->
它会同html标记一同发到客户端
2.jsp注释(3种)
形如<%--.............................--%>
它不会被发送到客户端,只用来注释服务器端的jsp文件,连jsp生成的servlet也没有注释进去,这也是大部分人使用的注释
形如<%//...... ......
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.Servl ......
jsp中include的两种形式: 1.<%@ include file=” ”%>
&nbs ......