JSP behavior for Java Development: jsp for java Development

Source: Internet
Author: User

JSP behavior for Java Development: jsp for java Development

I. Java Bean text

1. Highlights

Java Bean behavior is a set of Java Bean-related behaviors, including useBean behavior, setProperty behavior, and getProperty behavior. Java Bean is a common Java class. The Java Bean class is very simple. Only the private attributes and the corresponding getter method and setter method are supported. (Note: For boolean attributes, the getter method is generally written as isXxx () instead of getXxx ())

UseBean behavior attributes
Attribute name Value Range Description
Id Valid Java variable name

Specifies the name of the Java Bean object.

JSP can be used to reference the Java Bean object.

Class Full name of Java Bean class The full name of the Java Bean class.
Scope

Page,

Request,

Session,

Application

The scope of the Java Bean object.

When it is page, it is only valid in this JSP.

If it is a request, it is only valid in the current request.

This parameter is valid for the current user when it is a session.

When it is an application, it is valid in the current Web application. The default value is page.

 


2. Code practice

Scope implements various counters

Counter. java

 

1 package com. bean; 2 3 public class Counter {4 5 private int count; // Counter 6 7 public int getCount () {// each access, counter auto-increment 1 8 return ++ count; 9} 10 public void setCount (int count) {11 this. count = count; 12} 13}

 

Counter. jsp

1 <% @ page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> 2 <% 3 String path = request. getContextPath (); 4 String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; 5%> 6 7 <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 8 

3. Results

Ii. <jsp: plugin/> embed the Applet

1. Highlights

Java Applet is a Java Applet running in the client browser. JSP provides a set of plugin actions to simplify the embedded Applet operations. Plugin behaviors include <jsp: plugin/> <jsp: params/> <jsp: param/> <jsp: fallback/>. <Jsp: plugin/> is used to define a Java Applet in JSP and declare attributes such as the width and height of the Applet. <jsp: params/> is used to define a set of one-to-many parameters; <jsp: param/> is used to define a single parameter. <jsp: fallback/> is used to define substitution information when Applet is not supported.

2. Program practice

Plugin. jsp

1 <% @ page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> 2 <% 3 String path = request. getContextPath (); 4 String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; 5%> 6 7 <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 8 

3. Results

I don't know how to block it here.

 

Iii. <jsp: directive/> Behavior

<Jsp: directice/> the behavior is equivalent to JSP commands. <Jsp: directive. the page/> action is equivalent to the <% @ page %> command. <jsp: directive. the include/> action is equivalent to the <% @ include %> command. <jsp: directive. the taglib/> action is equivalent to the <% @ taglib %> command.

Note: The current Java Web development platform prefers to use direve ve instead of JSP commands. This is because <jsp: directive/> is more neat and readable than JSP commands.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.