Passing parameters between JSP pages is a function that is often used. Sometimes it is necessary to pass parameters between multiple JSP pages. The following article mainly introduces you to the relevant information about the method of passing values between JSP pages. What is introduced in the article It is very detailed and has certain reference and learning value for everyone. Friends who are interested in JSP should read it together below.
Preface
Passing parameters between JSP pages is often required in projects. This should be regarded as a basic skill on the web. Try to summarize various methods, and if necessary, you can weigh the pros and cons and choose the most appropriate method. Let’s take a look at the detailed introduction:
1. Append parameters after the URL link
<a href="next.jsp?paramA=A¶mB=B..." rel="external nofollow" >URL 后面追加参数</a> <jsp:include page="next.jsp"><jsp:param name="paramA" value="A"/></jsp:include> <jsp:forward page="next.jsp"><jsp:param name="paramA" value="B"/></jsp:forward> response.sendRedirect("next.jsp?paramA=A¶mB=B...") window.location = "next.jsp?paramA=A¶mB=B..."
The above codes will be carried when executed The parameters jump to the next.jsp page.
The way to get the corresponding parameters in the next.jsp page is as follows:
//内嵌的 java 代码 <%String paramA = request.getParameter("paramA"); %> //如果引入了 EL {param.paramA}
Advantages: Simplicity and multi-browser support (no browsing The server does not support URLs).
Disadvantages:
1) The transmitted data can only be string, both of data type and size Certain restrictions;
2) The value of the transmitted data will be seen in the browser address bar, and the security level is low.
2. Form
<form action="next.jsp" method="post"> <input type="text" name="paramA" value="A"> <input type="hidden" name="paramB" value="B"> <input type="submit" value="提交"> </form>
The method of obtaining the corresponding parameters in the next.jsp page is similar to (1).
Advantages:
1) Simplicity and multi-browser support (also no browser does not support form);
2) Can be submitted The amount of data is much larger than that of the URL method;
3) The transmitted value will be displayed in the address bar of the browser, but with some black tricks, the parameter list can also be constructed from the page source code;
Disadvantages:
1) The transmitted data can only be strings, and there are certain restrictions on the data type;
3. Set Cookie
Using the client's authentication credentials, a small cookie can of course also realize the value transfer of the JSP page.
<% Cookie c=new Cookie("paramA","A"); c.setMaxAge(60*60); //cookie 有效期1分钟 response.addCookie(c); //将cookie 添加到 http响应中 %>
If you want to read cookies on the next.jsp page, you need to call the request.getCookies()
method to obtain a javax.<a href="http://www.php.cn/wiki/1516.html" target="_blank">servlet</a>.http. Array of Cookie
objects.
Then iterate through this array and use the getName()
method and the getValue()
method to get the name and value of each cookie.
//内嵌的 java 代码 <% Cookie cookie = null; // 获取cookies的数据,是一个数组 Cookie[] cookies = request.getCookies(); if(cookies != null ){ for (int i = 0; i < cookies.length; i++){ cookie = cookies[i]; out.print("参数名 : " + cookie.getName()); out.print("<br>"); out.print("参数值: " + URLDecoder.decode(cookie.getValue(), "utf-8") +" <br>"); out.print("------------------------------------<br>"); } }else{ out.println("<h2 id="没有发现-nbsp-Cookie">没有发现 Cookie</h2>"); } %> //EL 获取方式 ${cookie.paramA.value}
Advantages:
1) The value of the cookie can be persisted. Even if the client machine is closed, the value inside can still be obtained next time it is opened;
2) Cookies can help the server save multiple state information, but do not require the server to allocate storage resources specifically, reducing the burden on the server.
Disadvantages:
1) Although the security is much improved compared to URL and Form, there are also black ways to obtain client cookies and expose customer information.
4. Setting Session
Personally, I think session and cookie are on the server side and one on the client side.
After adding key-value pairs to them, it not only provides transfer between pages, but is actually a data sharing solution.
<% session.setAttribute("paramA","A"); response.sendRedirect("next.jsp"); %>
How to read session in next.jsp:
//内嵌java 片段 <%=session.getAttribute("paramA") %> //EL 获取方式 {session.paramA}
The advantages and disadvantages of Session can be referred to Cookie.
The above is all the content of this article, I hope it can help everyone learn! !
Related recommendations:
Detailed explanation of how to directly access the JSP page in the WEB-INF directory
How ajax jumps to a new one Implementation method of jsp page
Method of function label EL expression provided by JSTL in JSP to operate string
The above is the detailed content of Summary of value transfer methods between JSP pages. For more information, please follow other related articles on the PHP Chinese website!

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version