A review of JSP and servlet knowledge

Source: Internet
Author: User

Jsp:

JSP page In addition to more than HTML Java code, instructions, and actions, the structure of the two basically similar.

JSP page embedded Java code <%java code%> form, to the page assignment multi-use <%=value%> form. Java code conforms to the Java syntax.

JSP common directives: Page,include and Taglib.

Page directive: Used to specify the global properties of the JSP, commonly used such as language, guide package, inheritance (not recommended), session is available, buffer size, Errorpage,contenttype and other properties.

Include directive: Loads the file code that needs to be inserted in the current JSP page, i.e. inserts a static page for the page. (Something similar to Android's include).

TAGLIB directive: Syntax format <%@ taglib uri= "Taglibraryuri" prefix= "TagPrefix"%>

URI: The location of the tag library that tells the JSP how to handle the label of the specified tag library. Prefix: Used to specify the prefix used for all action element names in the tag library.

JSP Common actions:

<jsp:param> can be used for include and forward, to transfer one or more parameters for other actions. Syntax: <jsp:param name= "parameter name" value= "argument value" >

<jsp:include><jsp:include page= "file name" flush= "true" ><jsp:parm name= "parameter" value= "parameter value" ></jsp> The fundamental difference with directives is the time they are called.

<jsp:useBean> the full path type= of the scope class= class used to load the name of the Bean<jsp:usebean id= "Bean instance you are using scope=" specifies the variable type that references the object " Beanname= "Specifies the name of the bean, must be used in conjunction with type, cannot be used in conjunction with Class" >

<jsp:setProperty> set or modify the name of the Bean<jsp:setproperty name= "Bean" that has been instantiated property= "property name" param= "Value" >

<jsp:getProperty> <jsp:getproperty name= "user" property= "UserName" >

JSP common built-in objects:

Out object, can output quite a lot of things. (Out.print (), out.get ...)

Request object, the client requests various information (get a heap ... )

Response object: Responds to various information about the client.

Session object: This is not much to say, very important.

PageContext: A page context that can interact well with other properties.

Exception: Handles JSP errors and exceptions.

Application: The entire Web application of the object, no life cycle, and the session is similar to the difference between a portrait is horizontal.

Servlet:

When the server initializes, the servlet's Init method is called, and the Destory method is called when it is destroyed, and the service method is invoked according to the request type to invoke the various specific methods in response.

The operation of a servlet is usually done in a specific requested method, where request and response can get the same thing as a JSP.

In fact, JSP is also servlet.

Here I also simply make a distinction between redirection and forwarding:

The most basic difference is that redirecting the user's browser URL will change, and forwarding will not.

Forward:
Request.getrequestdispatcher ("success.jsp"). Forward (Request,response);

Redirect:
Response.sendredirect ("success.jsp");

Through the code, it can be seen that forwarding is to distribute the request to another component to do processing, and will send requests and response over, which is why the request after the forwarding of things can be taken, and response is the original resopnse.

But redirection is not going to go, he just redirects it to another component, which is equivalent to requesting it again.

A review of JSP and servlet knowledge

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.