JSP userBean setProperty getProperty指令使用

javaBean的属性取决于get/set方法,而不是真实的属性名称。

jsp文件:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    pageContext.setAttribute("pca", "pageContextAttribute");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>009index</title>
</head>
<body>
    <jsp:useBean id="person" class="com.stono.servlet.bean.Person">
        <jsp:setProperty property="name" name="person" value="stono" />
    </jsp:useBean>
    <jsp:getProperty property="name" name="person" />
</body>
</html>

转换的java文件:

/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.35
 * Generated at: 2015-10-20 04:32:26 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;

public final class index009_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                  null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write(‘\r‘);
      out.write(‘\n‘);

    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    pageContext.setAttribute("pca", "pageContextAttribute");

      out.write("\r\n");
      out.write("<!DOCTYPE html>\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("<meta charset=\"UTF-8\">\r\n");
      out.write("<title>009index</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("\t");
      com.stono.servlet.bean.Person person = null;
      person = (com.stono.servlet.bean.Person) _jspx_page_context.getAttribute("person", javax.servlet.jsp.PageContext.PAGE_SCOPE);
      if (person == null){
        person = new com.stono.servlet.bean.Person();
        _jspx_page_context.setAttribute("person", person, javax.servlet.jsp.PageContext.PAGE_SCOPE);
        out.write("\r\n");
        out.write("\t\t");
        org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "name", "stono", null, null, false);
        out.write(‘\r‘);
        out.write(‘\n‘);
        out.write(‘    ‘);
      }
      out.write(‘\r‘);
      out.write(‘\n‘);
      out.write(‘    ‘);
      out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((com.stono.servlet.bean.Person)_jspx_page_context.findAttribute("person")).getName())));
      out.write("\r\n");
      out.write("\t\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

JavaBean:

package com.stono.servlet.bean;
public class Person {
    // 对外的属性名称还是name,
    private String name2;
    public String getName() {
        return name2;
    }
    public void setName(String name) {
        this.name2 = name;
    }
}
时间: 2024-10-20 10:06:26

JSP userBean setProperty getProperty指令使用的相关文章

JSP userBean setProperty直接从request中获取参数

JSP userBean setProperty直接从request中获取参数: form表单Jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page isELIgnored="true"%> <% String path = request.getContextPath(); String

JSP之使用useBean、setProperty、getProperty指令

useBean指令用于在JSP页面中初始化一个Java实例,setProperty指令用于为JavaBean实例的属性设置值,getProperty指令用于输出JavaBean实例的属性. 例子: JavaBean代码如下: package zhou; public class Person { private String name; private int age; public String getName() { return name; } public void setName(St

jsp笔记2(编译指令与动作指令)

一.jsp的编译指令是通知jsp引擎的消息,不会生成输出. jsp的3个编译指令: page:针对当前页面的指令   include:包含另一个页面的指令   taglib:用于定义和访问自定义标签 编译指令格式:  <%@ 编译指令名 属性="属性值"...%> page指令各属性的意义:       1.language:声明当前页面使用的脚本语言的种类,因为页面是jsp页面,故属性值通常是java,默认也为java    2.extends:指定jsp编译所产生的ja

JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用

Session的追踪技术 已知Session是利用cookie机制的服务器端技术,当客户端第一次访问资源时 如果调用request.getSession() 就会在服务器端创建一个由浏览器独享的session空间,并分配一个唯一且名称为JSESSIONID的cookie发送到浏览器端,如果浏览器没有禁用cookie的话,当浏览器再次访问项目中的Servlet程序时会将JSESSIONID带着,这时JSESSIONID就像唯一的一把钥匙  开启服务器端对应的session空间,进而获取到sessi

JAVAWEB开发之Session的追踪创建和销毁、JSP具体解释(指令,标签,内置对象,动作即转发和包括)、JavaBean及内省技术以及EL表达式获取内容的使用

Session的追踪技术 已知Session是利用cookie机制的server端技术.当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由浏览器独享的session空间,并分配一个唯一且名称为JSESSIONID的cookie发送到浏览器端,假设浏览器没有禁用cookie的话,当浏览器再次訪问项目中的Servlet程序时会将JSESSIONID带着.这时JSESSIONID就像唯一的一把钥匙  开启server端相应的session空

JSP中的编译指令和动作指令的区别

JSP中的编译指令和动作指令的区别 1.编译指令是通知Servlet引擎的处理消息,而动作指令只是运行时的脚本动作 2.编译指令是在将JSP编译成Servlet时起作用,而动作指令可替换成JSP脚本,是JSP脚本标准化写法

jsp两种include指令区别

[转]:http://www.cnblogs.com/lazycoding/archive/2011/04/04/two_include.html <%@ include file="relativeURI"%> <jsp:include page="relativeURI" flush="true" /> 首先说明这两种都是什么: <%@ include file="relativeURI"%&

JSP中的编译指令和动作指令的差别

JSP中的编译指令和动作指令的差别 1.编译指令是通知Servlet引擎的处理消息.而动作指令仅仅是执行时的脚本动作 2.编译指令是在将JSP编译成Servlet时起作用,而动作指令可替换成JSP脚本,是JSP脚本标准化写法

JSP userBean

scope=  "request"   "page"  "session"  "application"   (对应四个隐含对象) <jsp:userBean id="user" scope="request" class=""/> <%= user%><br> <%= request.getAttribute("u