Danh mục

Java Server Pages: A Code-Intensive Premium Reference- P4

Số trang: 10      Loại file: pdf      Dung lượng: 272.77 KB      Lượt xem: 12      Lượt tải: 0    
Thư viện của tui

Phí tải xuống: 1,000 VND Tải xuống file đầy đủ (10 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Server Pages: A Code-Intensive Premium Reference- P4:Before you begin reading Pure JSP Java Server Pages, you might want to take a look at its basicstructure. This should help you outline your reading plan if you choose not to read the text from cover tocover. This introduction gives you an overview of what each chapter covers.
Nội dung trích xuất từ tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P4 new FileInputStream(file.dat)); // Read the stored object and downcast it back to // a SimpleJavaBean value = (SimpleJavaBean)is.readObject(); is.close(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (ClassNotFoundException cnfe) { System.err.println(cnfe.getMessage()); } return value;}public void testBean() { // Create the Bean SimpleJavaBean simpleBean = new SimpleJavaBean(); // Use accessor to set property simpleBean.setSimpleProperty(simple property value); // Serialize the Bean to a Persistent Store storeBean(simpleBean); // Get the Bean from the Persistent Store SimpleJavaBean newBean = getBean(); System.out.println(The newBeans simpleProperty == + newBean.getSimpleProperty());}public static void main(String[] args) { SimpleJavaBeanTester simpleJavaBeanTester = new SimpleJavaBeanTester(); - 31 - simpleJavaBeanTester.testBean(); try { System.out.println(Press enter to continue...); System.in.read(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }}If you build and run this application, the output will look similar to the following:The newBeans simpleProperty == simple property valuePress enter to continue...Adding JavaBeans to JavaServer PagesNow that we understand what JavaBeans are and how they are commonly used, lets take a look atembedding them into JavaServer Pages. In the following sections, we are going to look at the standardactions used to reference JavaBeans and an example that uses these actions.JavaBean Standard ActionsThere are three standard actions defined to help integrate JavaBeans into JSPs: ,, and .The first standard action is . It associates an instance of a JavaBean defined with a givenscope and id via a newly declared scripting variable of the same id.The action is very flexible. Its exact semantics depend on the values of the givenattributes. The basic action tries to find an existing object using the same id and scope. If it does not findan existing instance, it will attempt to create the object. It is also possible to use this action only to give alocal name to an object defined elsewhere, as in another JSP page or in a servlet. This can be done byusing the type attribute, and by not providing the class or the beanName attribute. The syntax of the action is as follows: bodytypeSpec ::=class=className | class=className type=typeName | type=typeName class=className | - 32 - beanName=beanName type=typeName | type=typeName beanName=beanName | type=typeNameTable 3.1 contains the attributes of the action.Table 3.1: The Attributes for the ActionAttribute Definitionid This attribute represents the identity of the instance of the object in the specified scope. The name is case sensitive and must satisfy the current scripting languages variable naming conventions.scope The scope attribute represents the life of the object. The scope options are page, request, session, and application.class The fully qualified class name that defines the implementation of the object. The class name is case sensitive.beanName This attribute references the name of the bean, as expected to be instantiated by the instantiate() method of the java.beans.Beans class.type The type attribute specifies the type of scripting variable defined. If this attribute is unspecified, then the value is the same as the value of the class attribute.The second standard action to help integrate JavaBeans into JSPs is . It sets thevalue of a beans property. Its name attribute denotes an object that must already be defined and in scope.The syntax for the action is as follows:In the preceding syntax, the name attribute represents the name of the bean whose property you aresetting, and prop_expr can be represented in the following syntax:property=* |property=propertyName |property=propertyName param=parameterName |property=propertyName value=propertyValueTable 3.2 contains the attributes and their descriptions for the action.Table 3.2: The Attributes for the ActionAttribute ...

Tài liệu được xem nhiều: