Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JSP learns three instructions, nine built-in objects, JavaBean, and EL expressions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

JSP learns three instructions, nine built-in objects, JavaBean, and EL expressions

1. PageMutual-> the most complex:

PageEncoding and contentType:

PageEncoding: it specifies the encoding of the current jsp page, which requires pageEncoding when the server compiles jsp into .java.

ContentType: it identifies that adding a response header Content-Type is equivalent to response.setContentType ("text/html;charset=utf-8")

If only one of the two properties is provided, the default value of the other is the set one.

If neither property is set, the default is iso

Import: guide package! Can appear multiple times.

ErrorPage and isErrorPage

ErrorPage: if an exception is thrown on the current page, which page to forward to is specified by the errorPage attribute.

IsErrorPage: specifies whether the current page is a page that handles errors! When the property is true, the page sets the status code to 500! And this page can use exception from 9 built-in objects!

Error-page: you can set the jump page in web.xml when the jsp page is wrong.

four hundred and four

Error/404.jsp

five hundred

Error/500.jsp

Java.lang.RuntimeException

Error/error.jsp

AutoFlush and buffer

AutoFlush: specifies whether the output stream buffer of jsp is automatically flushed when it is full! The default is true, if it is false, then the buffer is full of exceptions!

Buffer: specifies the buffer size, which defaults to 8kb and usually does not need to be modified!

IsELIgnored: whether to ignore el expression. The default value is false. If not, it is supported!

The following properties are basically useless

Language: specifies the type of language currently compiled by jsp. The default value is java.

Info: information!

IsThreadSafa: whether the current jsp supports concurrent access!

Session: whether the current page supports session, and if it is false, then the current page does not have the built-in object session!

Extends: let the servlet generated by jsp inherit the class specified by this attribute!

2. Static include-> static

Similar to the function of RequestDispatcher's inchlude () method!

It is done when jsp is compiled into a java file, and together they generate a java file, and then a .class!

RequestDispatcher's include () is a method that contains and is contained two servlet, that is, two .class! They just merge the contents of the response at run time,

Function: decompose the page and group it together in an inclusive way, so that the constant part of a page is a separate jsp, and we only need to deal with the changed page.

3.taglibmuri-> Import tag library

* two attributes

Prefix: specify the prefix of the tag library on this page! We name it ourselves.

Uri: specify the location of the tag library!

Such as

=

Nine built-in objects

The output stream of out-- > jsp, used to respond to the client

Page-- > current jsp object! Its reference type is Object, that is, there is the following code in the real body: Object page = this

Config-- > it corresponds to the ServletConfig object in the real body!

PageContext-- > one tops nine.

Request-- > HttpServletRequest

Response-- > HttpServletResponse

Exception-- > Throwable

Session-- > HttpSession

Appliction-- > ServletContext

1.pageContext

There are three domains in Servlet and four domains in jsp, which is the last domain object!

ServletContext: the entire application

Session: entire session (there is only one user in a session)

Request: a chain of requests

PageContext: a jsp page! This field shares data between the tags used in the current jsp page and the current jsp page!

Domain object

Proxy other domains: pageContext.setAttribute ("xxx", "XXX", PageContext.SESSION_SCOPE)

Global search: pageContext.findAttribute ("xxx"); from small to large, dependent search!

=

JSP Action label

These jsp action tags are essentially different from those provided by html.

Action tags are interpreted and executed by the tomcat server! Like java code, it is executed on the server side!

Html tags are executed by browsers!

: forward! It is the same as RequestDispatcher's forward method, one used in servlet and one used in jsp!

Contains, which is the same as Requestdispatcher's include method.

*: it is used as a child tag of forward and include! Used to pass parameters to forwarded or included jsp pages.

=

JavaBean

The specification of javaBean:

1. You must have a default constructor

two。 Provide the get/set method, if only the get method, then this property is a system read-only property!

3. Attributes: there are members of get and set methods, and there can be no members, only get/set methods. The property name is determined by the get/set method! Not the member name!

4. If the method name meets a certain specification, then it is a property! Boolean type attribute, which can be read at the beginning of is or get!

Introspection:

Introspection class-- > Bean information-- > attribute descriptor-- > Method corresponding to the get/set of the attribute! -- > can reflect.

Commons-beanUtils, it is dependent on introspection to complete!

* Guide package:

Commons-beanUtils.jar

Commons-logging.jar

BeanUtils.getProperty (Object bean,String propertyName)

BeanUtils.setProperty (Object bean,String PropertyName,String propertyValue)

BeanUtils.populate (Map map,Object bean)

JavaBean-related tags in jsp!

Create or query bean

*

=

EL expression

1.EL is the expression language built into jsp pages!

Starting with jsp2.0, instead of using java scripts, use el expressions and dynamic tags instead of java scripts!

Instead of EL, that is to say, EL can only do output!

2.EL expression to read the four fields

${xxx}, looks around for an attribute named xxx, and if it doesn't exist, outputs an empty string instead of null.

${pageScope.xxx} ${requestScope.xxx} ${sessionScope.xxx} ${applicationScope.xxxx}, specify the domain to get the attribute!

Everything 3.EL can output is in 11 built-in objects!

We have learned four.

Param: the corresponding parameter, which is a Map, where key parameter name and value are parameter values, which are suitable for single-valued parameters.

ParamValues: corresponding parameter, which is a Map, where key parameter name, value is multiple parameter values, suitable for multi-valued parameters.

Header: corresponds to the request header, which is a Map, where key identifies the header name, and value is a single header value, which is suitable for single-value request headers.

HeaderValues: corresponding to the request header, it is a Map, where key identifies the header name, and value is multiple header values, which is suitable for multi-valued request headers.

InitParam: get the parameters under the node in the web.xml file

Cookie:Map type, where key is the name,value of cookie is the cookie object.

For example, ${cookie.JSESSTONID.value} can obtain the JSESSTONID stored in cookie

PageContext: it's a PageContext type! ${pageContext.request.contextPath} output the current project name

For example: href= "${pageContext.request.contextPath} / xx/aa/b.jsp"

=

EL function library (provided by JSTL)

Import tag Library

Specific library method: https://docs.oracle.com/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/fn/tld-summary.html

Boolean contains (string, substring) boolean containsIgnoreCase (string, substring) boolean startsWith (string, prefix) boolean endsWith (string, suffix) String [] split (string, separator) String substring (string, begin, end) String substringBefore (string, substring) String substringAfter (string, substring) String replace (string, before, after) String toLowerCase (string) String toUpperCase (string) String trim (string) string (int indexOf, int indexOf) int indexOf (string, string) string (string) string []

* calling method: ${fn:length}

=

Custom function library

Write a java class, which can define 0n methods, which must be static methods and must have a return value.

Create a tld file in the WEB-INF directory

Import tag libraries in the jsp page

Use a custom library in the jsp page: ${it:fun ()}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report