ASCII码 ASCII码

JSP JavaBean的setProperty属性

发布于:2022-03-30 13:05:25  栏目:技术文档
  1. JSP JavaBean的setProperty属性
  1. JSP JavaBean的setProperty属性使用实例。
  2. 1.包:
  1. package PaintBrush;
  2. /**
  3. *
  4. * @author lucifer
  5. */
  6. public class PaintBrush {
  7. private String curcolor = "red";
  8. public String getColor(){
  9. return curcolor;
  10. }
  11. public void setColor(String color){
  12. curcolor = color;
  13. }
  14. }
  1. 2.JSP代码:
  1. <%--
  2. Document : TestSetPro
  3. Created on : 2009-10-3, 15:02:50
  4. Author : lucifer
  5. --%>
  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  8. "http://www.w3.org/TR/html4/loose.dtd">
  9. <jsp:useBean id="brush" class="PaintBrush.PaintBrush"/>
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  13. <title>JSP Page</title>
  14. </head>
  15. <body>
  16. Original Color:
  17. <jsp:getProperty name="brush" property="color"/>
  18. <br>
  19. Changed Color:
  20. <jsp:setProperty name="brush" property="color" value="blue"/>
  21. <jsp:getProperty name="brush" property="color"/>
  22. </body>
  23. </html>
  1. 3.输出:
  2. Original Color: red
  3. Changed Color: blue
相关推荐
阅读 +