JSP (1): Web development basics, JSP syntax and built-in objects

Source: Internet
Author: User
Tags table definition

1. A server, a host in the network, which provides network services such as web and FTP.

2. During the request response process, if a static html webpage is stored on the server, the server will return the content in the webpage intact. If a dynamic webpage is stored, the server executes dynamic web pages. The result is to generate an HTML file and send it to the client browser. The client browser interprets the file as the page you see.

3. jsp supports cross-platform and reusable services.

4. High execution efficiency: When a JSP is requested for the first time, the JSP page is converted into a Servlet and then compiled *. class, file, and later (unless the page has been changed or the web server has been restarted) and then the customer requests the JSP page. The JSP page is not re-compiled, but is directly executed *. class file, so the execution efficiency is high.

5. asp disadvantages: the script language cannot perform underlying operations such as traditional programming; the execution efficiency is low by interpreting and executing the Code; the script and HTML code are mixed together, which is not easy to manage and maintain.

6. php defects: it does not support Object-Oriented Programming in the true sense, interface support is not uniform, lack of formal support, and does not support multi-layer structures and distributed computing.

7. jsp running principle: when a user enters a request in the address bar, such as requesting myfirst. JSP, The myfirst. JSP pages generate requests. When the myfirst page on the server is requested for the first time, the JSP Engine first translates the JSP page file and generates a Java file, which is essentially a assumervlet file, the file name is myfirst_jsp.java. the JSP Engine calls the Java compiler to compile this file to form a Java bytecode file: myfirst_jsp.class. In response to the customer request, the result of executing myfirst_jsp.class is to send an HTML file to the client.
When the page is requested again, the JSP Engine will directly execute this bytecode file to respond to the customer's request.
When multiple customers request the same JSP page at the same time, the Tomcat server starts a thread for each customer, which executes the bytecode file resident memory to respond to the customer's request.

8. servlet: the Java class written using the relevant classes and methods of the Java Servlet API is the servlet class. Objects generated by the servlet class can access various resources of Servers configured with JSP runtime environments.

9. jsp tags, Java code, and JSP pages can be embedded into the servlet and executed to respond to customer requests.

10. JavaBean: a reusable software component. In fact, JavaBean is a Java class, which is generally responsible for the business logic processing part of the Web application system. The object instantiated by the JavaBean class is called Bean.

11. JSP + JavaBean mode: JSP is responsible for page implementation, page preprocessing, and jump control, and JavaBean is responsible for business Roger data processing. Small-scale web applications

12. JSP + JavaBean + servlet mode: JSP is responsible for page processing, JavaBean is responsible for business logic and data processing, servlet is responsible for preprocessing and distribution of page requests. Large-scale web applications.

13. Sun calls JDK 1.3 and later versions Java2 ~ 1.6 ).

14. Form: A form is used to collect and submit user input information on a webpage. It is an interactive window between a website and its visitors.

15. Form tag <form action = ""...> action: the URL of the program that processes the data submitted by the form. If it is null, the URL of the current document is used.

16. enctype attribute in the form: Specifies the encoding method used by the browser when data is sent to the server.

17. Method in the form: Post: the address bar does not see the form's submission information. The amount of data transmitted is much larger than the get method. Get: You can see in the address bar that the transfer volume is generally less than 1 kb.

18. Input Tag: <input name = "" type = ""> name: name of the input area of the form. Type: defines the type of the input area of the form. There are 10 types.

19. CSS rule definition: Selector {property: Value} For example: body {color: Green}
There are three types of selectors: Tag selector P {attribute: Value}, Id selector: If the <p id = "red"> Red </P> in HTML, # Red {color: red}; class selector: such as <H1 class = "red"> Red Multiple Attributes are separated by commas (,). If multiple selectors are grouped and the same rules are shared, each selector is separated by commas.

20. Add a style sheet: 1. Define an internal style block object: 2. inline definition: Use the style attribute of the object to define the corresponding style table in the object label, for example, <P style = "color: Red"> Red </P>
3. Connect the external style sheet: first create the external style table file .css, and then use the link object in the

21. javascript: an object-oriented and event-driven scripting language with secure performance. It is an explanatory language.

22. If a static object is in Javascript, you do not need to create an instance for the object when referencing its attributes or methods, A dynamic object is created when its object or method is referenced.

23. javascript can be inserted anywhere in HTML, but if you want to insert it in the webpage of the declared framework, it must be placed before <frameset>; otherwise, it will not be executed.
There are two insert methods:
1. <script language = "JavaScript"> <! ----> </SCRIPT>
2. Write JavaScript code to another file. JS is the extension, and then <SCRIPT src = "Java Script. JS "> </SCRIPT> label to embed it into the document.

24. Any type in javascript can be converted to one another, but it must be assigned a value before use.

25. Javascript operator three equal signs: =: true only when the types on both sides are always and the values are equal .! =: True when the type is different or the type is the same but the value is not equal.

25. Use the Keyword: function when defining JavaScript functions. This indicates the current object rather than the pointer.

26. Use with in JavaScript to specify the default object: With (Object Name) {statement sequence}

27. jsp comments: <% -- Comments -- %> or <%/** comments **/%>
The comments that customers can see are also known as embedded comments: <! -- Comments --> is displayed in the browser. The JSP engine does not provide any explanation. Dynamic Data can appear in this comment, and the dynamic data in the watch is expressed by expressions. Example: <! -- Comment <% = expression %> comment -->, such as: <! -- The current time is: <% = (New java. util. Date (). tolocalestring () %> -->

28. jsp declaration element format: <%! Statement %>. For example, declare an integer variable I: <%! Int I; %> or directly assign the initial value <%! Int I = 1; %>, declare a method: <%! Public void add () {I = m + n ;}%>

29. jsp expression: <% = expression %> after execution, it is automatically converted to a string and displayed.
Note: The semicolon ";" cannot be used as the expression ending symbol.
In servlet, the processing expression only overpacks the JSP expression out. println () method.

30. jsp Commands include page commands, include commands, and taglib commands. It is not output to the client, and the valid range is limited to the JSP page that uses this command. Format: <% @ command name attribute 1 =, property 2 =,... %>

31. Page command: Except for the import attribute, other commands can only use the page command to set a value for this attribute once, even if the set value is equal. Example: <% @ page import = "Java. util. *", "Java. Io. *", "Java. SQL. *" %>

32. Currently, only Java is supported in the language attribute of page;
Session attribute: Specifies whether the page is involved in an HTTP session. The value is true or false. The iserrorpage attribute is as follows: set whether the current JSP page can be used as the error handling page of another page to true or false;
Errorpage: Set the page to be switched when an exception occurs on the JSP page.
Contenttype: Specifies the JSP character encoding and the MIME type corresponding to the JSP page.

33. The contenttype values are as follows:
Text/html: webpage display (default );
Application/MSWord: Word document format display
Application/vnd. MS-Excel: displayed in an Excel table
Application/vnd. MS-PowerPoint: displayed as a PowerPoint presentation

34. include command element: include another file to the current JSP page. This file can be either a text file or a JSP file. For example, <% @ include file = "logo.html" %>. This process is static.

35. taglib command element: defines a tag Library and the prefix of custom tags. Syntax: <% @ taglib url = "extension tag URL" prefix = "extension tag prefix" %>

36. jsp standard operation commands:
Include action: Add static and dynamic resources to the current JSP page. Parameters can be passed. For example:
<JSP: Include page = "url">
<JSP: Param name = "parameter name 1" value = "value 1">
<JSP: Param name = "parameter name 2" value = "value 2">
</Jsp: Include>

37. Differences between include commands and include actions:
Can complete file inclusion,
Difference: The include command can only insert files statically. The command is executed during compilation, that is, the content in the file to be inserted is inserted into the current webpage during compilation to generate a Java file; the include action is to insert files dynamically. during compilation, the file content to be inserted is not inserted into the current webpage, and the operation is executed when receiving requests.
So when the insert file changes, the include Command Re-compiles the current page to generate a new Java file. Otherwise, the current page will not change, and the include operation will not recompile.

38. forward operation: forwarding a request sent by a customer from one JSP page to another JSP page will cause the request target on the Web server to be forwarded. Note: The program after the <JSP: Forward> label cannot be executed. You can pass parameters, which are the same as include parameters.

39. plugin operation: This command ensures that a Java Plug-in software is available and can display or play an object (Applet and bean) in a browser ). Syntax format:
<JSP: plugin type = "bean | applet" code = "save class file name" codebase = "class path">
<JSP: Params>
<JSP: Param name = "parameter name 1" value = "value 1">
<JSP: Param name = "parameter name 2" value = "value 2">
</Jsp: Params>
<JSP: fallback> error message </jsp: fallback>
</Jsp: plugin>
The plug-in is not started. <JSP: fallback> an error message is provided. If the plug-in has been started but the applet or bean has not been started, a window is usually displayed to inform the user of the error.

40. usebean action: defines the JavaBean object to be used in the JSP webpage.

41. The out object is a subclass object of the javax. servlet. jsp. jspwriter class. Its function is to send information back to the browser of the client. The lifecycle of an out object is the current page. Each JSP page has an out object. Common methods include print (), println (), write (), newline (), flush (), and close.

42. Request object: the object of the javax. servlet. httpservletrequest subclass. When the client requests a JSP page, the JSP Container will wrap the request information of the client in this request object. The format is string strusername = request. getparameter ("userid ");

43. Request: setattribute (name, value): set the value of the request parameter named name, which is specified by "value. Getattribute (name): Get the parameter value specified by name

44. Man encoding: When request. getparameter is used to get the elements in form, the default character encoding is: ISO-8859-1, which cannot correctly display Chinese characters. Solution:
① Before the execution, set the Request Encoding format: request. setcharacterencoding ("GBK ");
② Conversion character encoding: <% string STR = request. getparameter ("boy ");
Byte B [] = Str. getbytes ("ISO-8859-1 ");
STR = new string (B); %>

45. Response object: a subclass object of the javax. servlet. http. httpservletresponse class. Its role is to encapsulate the response generated by the JSP program and send it to the client.

46. webpage redirection: sendredirect () is redirected to a new page, and the redirected code will not be executed.

47. Differences between sendredirect () and <JSP: Forward>:
① Sendredirect () can transmit parameters without directly coding the URL, for example: Response. sendredirect ("example. jsp? P = 234 ") transfer parameter P, value: 234
② <JSP: Forward> data can be shared between two pages through the request object, which is not supported by sendredirect.

48. The contenttype attribute can be dynamically set in response. The MIME types include PDF, word, and excel.

49. Session: a client opens a browser and connects to the server until the client closes the browser.

50. session ID: when a client establishes a connection with the server through a browser and sends the first request, the server will assign the client a session object, the Session object is assigned a string-type ID number. the JSP engine sends the ID to the client in response to the customer's request and writes it to the client's cookie, in this way, the server can identify a customer through different session IDs and share data across webpages.

51. Summary: The session ID will not change as long as the browser is not closed

52. Session end: if the session is cleared from time to time, the storage space of the server will be exhausted. Generally, a 30-minute session expiration time is set by default on the server, so that the session object will automatically expire after the customer stops the activity.

53. Set the session timeout period. You can use setmaxinactiveinterval () of the session, or use web. the XML file is deployed on Tomcat, that is, on the web. find the corresponding <session-Timeout> tag in XML and set the change time. When no session is required, you can use the invalidate () method of the session to close a session.

54. The application object takes the role of the server. The startup and shutdown of the server determine the application lifecycle. When any JSP is started, the application is terminated on the server. All threads of each application share this application object.

55. application is an instance of the javax. servlet. servletcontext class.

56. The getattribute method of the application returns an object-type data, which must be converted during use.

57. Application can be applied to website counters. If you do not want to count the same user when refreshing a Web page, you can use session. isnew () to judge.

58. Cookies are small plain text files sent by the server to the browser. They will be sent to the server as they are when users access the same web server. By allowing the server to read the information they originally stored on the client, it provides a series of conveniences. For example, if the user identity is identified during online transactions and the security performance is not high, users are not allowed to repeatedly enter their names and passwords, customize the portal's homepage, and place advertisements in a targeted manner.

59. The size of each cookie is limited to 4 kb. Generally, a browser can only store 300 cookies, and each site can store up to 20 cookies. Therefore, it will not fill the customer's hard disk.

60. Create a cookie: cookie = new cookie (cookie name, "content ");

61. Read cookie value: the getcookie () method reads the cookie value in the program and returns an array containing the values of all cookies. For example:
Cookie [] array name = request. getcookie ();
Every cookie variable is retrieved cyclically;
Cookie variable. getname ();
Cookie variable. getvalue ();

62. config object: used to initialize Parameters

63. Exception object: When an exception occurs to a JSP object during running, the result of the called error page is generated (the iserrorpage attribute value is true)

64. Page Object: refers to the JSP itself, as if referencing this

65. pagecontext object: used by the servlets code generated by the JSP Engine to access various available scopes in JSP.

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.