JavaSercer Pages The JSP 1.1 specification defines that (Servlets hosting)

JavaSercer Pages The JSP 1.1 specification defines that an attribute named id typically is used to name a variable created by an action.7 The value of the id attribute must be unique within the page. Because it’s used as a scripting variable name, it must also follow the variable name rules for the scripting language. For Java, this means it must start with a letter followed by a combination of letters and digits, and must not contain special characters, such as a dot or a plus sign. The attribute used in another action to refer to the variable can be named anything, but the convention established by the standard actions is to call it name. When a custom action creates a variable, it must cooperate with the JSP container to make it happen. To understand how this works, recall that the JSP page is turned into a servlet by the JSP container. The JSP container needs to generate code that declares the scripting variable in the generated servlet and assigns the variable a value. Before getting into how the tag handler and the container cooperate, let’s look at the kind of code that is generated for the custom action introduced in Chapter 8. Here’s a JSP page fragment: <% prod.getName( ); %> The action creates an instance of the CatalogBean (or locates an existing instance) and saves it in the page scope with the name catalog. It also declares a scripting variable named catalog and sets it to the same CatalogBean instance. The custom action retrieves the product property from the CatalogBean and introduces it as a page scope object named prod and a scripting variable with the same name, in the same manner as the action. Finally, the value of prod is added to the response twice: first using the action, and then again using a JSP expression. This JSP page fragment results in code similar to Example 16.5 in the generated servlet. Example 16.5. Code Generated for JSP Actions // Code for com.ora.jsp.beans.shopping.CatalogBean catalog = null; catalog= (com.ora.jsp.beans.shopping.CatalogBean) pageContext.getAttribute(”catalog”,PageContext.PAGE_SCOPE); if ( catalog == null ) { try { catalog = (com.ora.jsp.beans.shopping.CatalogBean) Beans.instantiate(getClassLoader( ), “com.ora.jsp.beans.shopping.CatalogBean”); } catch (Exception exc) { throw new ServletException (”Cannot create bean of class “+ “com.ora.jsp.beans.shopping.CatalogBean”); } pageContext.setAttribute(”catalog”, catalog, PageContext.PAGE_SCOPE); } … // Code for com.ora.jsp.tags.generic.UsePropertyTag _jspx_th_ora_useProperty_1 = new com.ora.jsp.tags.generic.UsePropertyTag( ); _jspx_th_ora_useProperty_1.setPageContext(pageContext); _jspx_th_ora_useProperty_1.setParent(null); _jspx_th_ora_useProperty_1.setId(”prod”); _jspx_th_ora_useProperty_1.setName(”catalog”); _jspx_th_ora_useProperty_1.setProperty(”product”); _jspx_th_ora_useProperty_1.setArg(”1″); _jspx_th_ora_useProperty_1.setClassName( “com.ora.jsp.beans.shopping.ProductBean”); try { _jspx_th_ora_useProperty_1.doStartTag( ); if (_jspx_th_ora_useProperty_1.doEndTag( ) == Tag.SKIP_PAGE) return; } finally { _jspx_th_ora_useProperty_1.release( ); } com.ora.jsp.beans.shopping.ProductBean prod = null; prod = (com.ora.jsp.beans.shopping.ProductBean) pageContext.findAttribute(”prod”); … // Code for out.print(pageContext.findAttribute(”prod”), “name”))); … // Code for <%= prod.getName( ) %> out.print( prod.getName( ) ); 7 If an action creates more than one variable, the id attribute is typically used to name one of them. page 224
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services

Comments are closed.