Several Methods for passing parameters on JSP pages

Source: Internet
Author: User

1. Javascript parameter passing: this parameter passing method uses the opener keyword to implement cross-page parameter passing. Its usage is to use the opener keyword to call a component of the parent form.

Example: opener.myform.txt. value = document.myform.txt. value;

Advantage: it is simple, and limits on network transmission are relatively low.

Disadvantages: not flexible. It is neither realistic nor practical to transmit a large number of parameters.

2 ."? "Parameter passing: add? The parameter name and value are followed. You can use request. getparameter ("parameter name") on another JSP page to obtain the passed parameter.

Example: http: // localhost: 8080/BBS/tiezi/jishu. jsp? Id = 1

Advantage: flexible, you only need to put the parameters to be passed into a variable and pass them to the passed interface.

Disadvantage: it is unrealistic to PASS Parameters in batches.

3. session parameter passing: it is usually used to maintain the state. there are two parameters in the session. The first parameter is the identifier, and the second parameter is the value. In the form ("key", "value"), if your thinking is agile, you can think of a scattered list, this is an implementation of the hash.

Example: Session. setattribute ("login", "OK"); Session. getattribute ("login ");

Advantage: you do not need to care about any data types. You can put them in the session. They are stored in the hash as objects.

Disadvantage: All data in the session is accessed as an object, so we need to forcibly convert the type to the type we need every time we use it.

4. javaBean parameter passing: This is the highest-level parameter passing. It encapsulates any data type and method in JavaBean. we can define the parameters to be passed in the attributes, and then add a get and set methods. We can set the lifecycle of parameters to complete the process of passing parameters when calling in JSP.

Example:

package bean;public class sampleBean{private String sample="Star value";public String getSample(){return sample;}public void setSample(String newsample){if(newsample!=null){sample=newsample;}}}

Advantages: flexible and diverse, passing data structures such as arrays, objects, hash tables, and so on.

Disadvantage: It is time-consuming and labor-consuming to write different JavaBean based on different passing parameters.

Everything has its advantages and disadvantages. Everything has two sides. We cannot use one transmission method unilaterally. We should choose one transmission method based on the actual situation and actual needs.

Reprinted from http://www.soft6.com/news/200708/29/111244.html

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.