JSP Day 2

Source: Internet
Author: User

<JSP: usebean id = "today" class = "Java. util. Date" Scope = "request"> </jsp: usebean>
==>
Object o = request. getattribute ("today ");
If (o! = NULL ){
Date today = (date) O;
} Else {
Date today = new java. util. Date ();
Request. setattribute ("today", today );
}
The class is first searched. If it cannot be found, a new object is created and the attribute is set in the range.

<JSP: usebean id = "today" type = "Java. util. Date" Scope = "request"> </jsp: usebean>
==>
Object o = request. getattribute ("today ");
If (o! = NULL ){
Date today = (date) O;
} Else {
Throw new exception ("unable to find the information named today in scope ");
}
Type is searched first. If no value is found, an exception is reported.
Applicable to multi-state environments

<JSP: setproperty property = "Birthday" name = "p" value = "<% = request. getparameter (" Birthday ") %>"/>
==>
String Birthday = request. getparameter ("Birthday ");
P. setbirthday (birthday );

<JSP: setproperty property = "name" name = "p"/>
==>
String name = request. getparamter ("name ");
P. setname (name );
If no value is set, the system queries parameters with the same name from the page by default. Set the value

<JSP: setproperty property = "*" name = "p"/>
="
Get all attribute names in object P
Use each attribute name as a parameter name to find the parameter values on the page.
Set Object Property Values

========================================================== ========
Prerequisites:
Control name = property name in the object class on the page
========================================================== ========

<JSP: getproperty property = "name" name = "p"/>
="
P. getname ();

The role of the page:
1. Accept user input data
<Form...>
2. Obtain the data stored in a certain range and present the data to the client.
<JSP: usebean id = "" type = "" Scope = ">

Jump path:
We recommend that you use absolute path, that is, starting /.
In HTML and redirect redirection,/Application name/request...
In forward jump,/request...

Java code left in JSP:
1. Code for getting data
Parameters
Attribute
System internal information
2. Logical branches and cyclic statements

El: Expression Language
Syntax structure:
$ {...}
Purpose:
Obtain and display data
Data includes:
* Parameters
$ {Param. parameter name}
="
Request. getparameter ("parameter name ");

$ {Paramvalues. parameter name}
Obtain multiple parameter values with the same name
Request. getparametervalues ("parameter name ")
* Attributes
$ {Attribute name}
="
Pagecontext. findattribute ("attribute name ");

Pagecontext ----- indicates the current Web Application
Getattribute ("attribute name", range)
Pagecontext. request_scope
Pagecontext. session_scope
Pagecontext. application_scope
Setattribute ("attribute name", "attribute value", Set range)
Pagecontext. request_scope
Pagecontext. session_scope
Pagecontext. application_scope
Findattribute ("attribute name ")
Request ==> session ==> search for properties in the application in sequence, locate and stop. If no value is found, null is returned.

$ {Built-in object name. attribute name}
==>
Pagecontext. getattribute ("attribute name", built-in object name)
* Internal system information
$ {Pagecontext. Object Name ....}
El common built-in objects
Requestscope
Sessionscope
Applicationscope

Supported data in El:
 
<Integer_literal>
<Floating_point_literal>
<String_literal>
"True", "false"
"Null"
"("
"-"
"Not"
"! "
"Empty"
<Identifier>
 
Operators supported in El:
"}",". ","> "," GT "," <"," LT "," = "," EQ "," <= "," Le ", "> =", "Ge ","! = "," Ne "," ["," + ","-"," * ","/"," Div "," % "," Mod ", "and", "&", "or", "| ","? "

 
Pagecontext. getrequest (): servletrequest
Request. getcontextpath ();
==>
$ {Pagecontext. Request. contextpath}

 

 

 

Related Article

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.