In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how JSP implements dynamic web programs. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In form, JSP pages add Java program fragments (Scriptlet) and JSP tags to the traditional web page HTML files. When the Servlet/JSP container receives the request from the client, it first executes the program fragment, and then responds to the client in HTML format.
Basic syntax:
Note:
1. Comments that can be seen by the client: (dynamic expressions can be added to annotations)
2. Developer-specific comments: or
Declaration:
The declared variable is a class variable. This means that if n users are executing this JSP page at the same time, they will share this variable. Can cause trouble in thread synchronization. (not recommended)
Small script:
This kind of defined variables are local variables, there is no problem of multi-thread synchronization, and it is thread-safe.
Expression:
You cannot use ";" as the closing symbol of an expression.
JSP instruction element:
Just tell the JSP engine how to compile the JSP page.
Page directive: set the properties and related functions of the entire JSP page.
For example:
Include directive: instructs the JSP container to insert a file containing text or code when JSP is compiled, which is static. Note that use should be avoided in the include file, which may lead to errors.
For example:
Taglib directive:
JSP operation element:
Submission of request objects and network information:
The request object is provided in JSP to receive the data sent back by the client.
General syntax of ◆ URL: protocol://host:port/virtualPath?queryString
◆ protocol: represents a protocol that declares a low-level mechanism (http ftp https, etc.) for transferring information between remote machines.
◆ host: represents the name or ip address of the remote machine to which the request is sent.
◆ port: declares the machine port number on which the server will listen for requests.
◆ virtualPath: contains a set of identifiers with slashes as delimiters that the server maps to a physical path and the location of the JSP.
◆ querString: is a query string, which is a paired list of names and values, passed as an argument to the JSP to the JSP page that processes it. If you have more than one parameter to pass, the names and values in pairs are separated by a "&" sign.
The methods provided by the request object:
Get path and protocol information:
String getProtocol () gets the protocol and version number used for communication (e.g. HTTP / 1.1) String getScheme () gets the protocol name in the request (e.g. HTTP) String getPathInfo () gets the additional information in the request between the JSP path and the query string String getContextPath () String getRequestURI () String getServletPath () String getRealPath (String path)
Get host and port information:
String getServerName () gets the name of the server that responded to the request. Int getServerPort () gets the server-side host port number that responds to the request. String getLocalName () gets the server-side hostname that responded to the request. String getLocalAddr () gets the server-side address that responds to the request. Int getLocalPort () gets the server port that responds to the request. String getRemoteAddr () gets the IP address of the client that made the request. String getRemoteHost () gets the hostname of the client that made the request. Int getRemotePort () gets the port of the client host that made the request.
Get the query string:
String getQueryString () gets the parameter string passed by the get () method, that is, in URL? The back part.
Get the variable value in the query string:
String getParameter (String name) gets the parameter values that the client sends to the server. Enumeration getParameterNames () returns a collection of all the parameters in the request. String [] getParameterValues (String name) gets all the values of the parameters specified in the request.
For example:
Http://localhost:8080/liuxl/jsp/querystring.jsp?str=JSP String s=request.getParameter ("str"); gets the value of the variable str, and the value of s after execution is "JSP".
Note: the return value of the getParameter () method can only be a string. If you pass val=100, you need to do a type conversion.
If (request.getParameter ("val")! = null) / / determines whether the string is empty {num=Integer.parseInt (request.getParameter ("val")); / / converts the string to an integer} else {num=0 } if (request.getParameter ("val")! = null) / / determines whether the string is empty {num=Integer.parseInt (request.getParameter ("val")); / / converts the string to an integer} else {num=0;}
Forms and their applications in information transmission:
Form:
Is an area that can contain form elements, HTML provides a variety of graphical user interface component elements for the form (such as text box, password box, drop-down menu, etc.), these form elements allow users to enter information in the form, you can use them to form content, as a field that the user can enter, and can submit it to a JSP for processing.
Format:
...
Where: name is used to specify the name of the form. Action is used to specify the action to be performed when the form is submitted. Method specifies the method (GET, POST, PUT, commonly used POST) by which the request is delivered to JSP.
1. Tags are often used to enter or submit information
Syntax:
Description: type allows you to specify input types (text (text box), password (password box), checkbox (check box), radio (radio button), image (image field), reset (reset button), submit (submit button). Name is the name of the form element. Value is the initial value of the form element.
For example:
Text box: password box: submit button: reset button: radio button:
(used to select one of the options from a set of options, checked is an optional attribute, which indicates that the button is selected when displayed, otherwise it is not selected. )
E.g: option 1 option 2
Submit the URL with button 1 selected as follows:...? radiobutton=1...
Check box:
(used to select multiple options from a set of options, checked as above. Like radio buttons, check boxes are often used in groups. Unlike radio buttons, multiple selected check boxes are submitted, so their name can be the same (processed as an array) or different (processed as different variables).
E.g:swim run
If both are selected at the time of submission, the URL is in the following form:...? checkbox=swim&checkbox=run...
2. The label declares an area where users can enter multiple lines of text
Syntax: text
Description: cols is the width of the text field (number of characters), rows is the height of the text field (number of lines)
3. The tag declares a list of options, and the user can select one or more options.
Option... Option
Description: name is the name, size is the height of the list area (that is, the number of options that can be displayed), multiple is an optional attribute, and multiple items can be selected if there is one. Selected is an optional attribute, indicating that the option is set to selected.
Thank you for reading! This is the end of the article on "how to implement dynamic web programs in JSP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.