Home  >  Article  >  Java  >  How to transfer data between jsp pages

How to transfer data between jsp pages

(*-*)浩
(*-*)浩Original
2019-05-18 19:42:443261browse

HTTP is a stateless protocol. The Web page itself cannot pass information to the next page. If the next page needs to know the value in the page, it cannot pass the server. Therefore, it is an important technology for Web pages to maintain state and pass it to other pages.

How to transfer data between jsp pages

Transferring data between Web pages is an important function of Web programs

Here are two methods to complete this matter:

1) URL passes value;

2) Form passes value;

1. URL passes value

Pass the value in page 1 Give page

index.jsp page:

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<title>My JSP 'index.jsp' starting page</title>
<meta>
<meta>
<meta> 
<meta>
<meta>



该数的平方为: <hr>
<a>">到达get_index</a> 

get_index.jsp page

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

   
    <title>My JSP 'get_index.jsp' starting page</title> 
	<meta>
	<meta>
	<meta>    
	<meta>
	<meta>
   
  
    
     	该数字的立方为: <hr>
  

page display results:

How to transfer data between jsp pagesHow to transfer data between jsp pages

Advantages:

Simplicity and diversity of platform support (no browser does not support URLs).

Disadvantages:

1) The transmitted data can only be strings, and there are certain restrictions on the data type;

2) The transmission of data The value will be visible in the browser address bar, which is unsafe from a privacy perspective. Especially data with strict confidentiality requirements, such as passwords.

2. Values ​​passed through the form

The value passed through the URL in method 1 will be seen. In order to avoid this problem, we can use the form to pass the value in page 1 The variable is passed to page 2.

index.jsp:

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  
    <title>My JSP 'index.jsp' starting page</title>
	<meta>
	<meta>
	<meta>    
	<meta>
	<meta>
  
  
  
   	该数的平方为:  <hr>
   	
    ">        
  

get_index.jsp:

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

   
    <title>My JSP 'get_index.jsp' starting page</title> 
	<meta>
	<meta>
	<meta>    
	<meta>
	<meta>
   
  
    
     	该数字的立方为: <hr>
  

The page displays the results:

How to transfer data between jsp pagesHow to transfer data between jsp pages

This method successfully transfers the value, and the transferred information cannot be seen. If you want to hide it in the text box, change type="text" to type="hidden" to hide it.

Problems with this method:

1) Similar to the URL method, the data transmitted by this method can only be strings, and there are certain restrictions on the data type. ;

2) Although the value of the transmitted data can be guaranteed not to be seen in the browser address bar, it will also be seen in the client source code. From the perspective of confidentiality, this is unsafe of. For data with strict confidentiality requirements, such as passwords, it is not recommended to use forms for transmission.

The above is the detailed content of How to transfer data between jsp pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn