JSP case _ pass Cookie value, jsp case _ cookie

Source: Internet
Author: User

JSP case _ pass Cookie value, jsp case _ cookie

JSP case _ Cookie value passing

1. Case requirements

Create a producer.

When the user enters the secondary node for the second time within 30 seconds

2. Case Analysis

Use the Cookie to pass the value and set the Cookie time, that is, 30 seconds. In the time range, enter

3. Code Analysis

Code implementation is not difficult. It mainly involves the use of Cookie APIs and a logical relationship.

4. Code

Https://blog.csdn.net/ag_nevergiveup/article/details/a.jsp:

<% @ Page import = "java.net. URLDecoder "%> <% @ page import =" java.net. URLEncoder "%> <% @ page import =" org. apache. taglibs. standard. tag. common. core. forEachSupport "%> <% @ page language =" java "import =" java. util. * "pageEncoding =" UTF-8 "%> <% request. setCharacterEncoding ("UTF-8"); Cookie [] cookis = request. getCookies (); String username = ""; String userpassword = ""; if (cookis. length> 1) {for (int I = 0; I
 
  
Register
 
D. jsp:
<%@page import="java.net.URLEncoder"%><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%request.setCharacterEncoding("utf-8");String name = request.getParameter("name");name = URLEncoder.encode(name, "utf-8");String password = request.getParameter("password");Cookie c1 = new Cookie("name",name);Cookie c2 = new Cookie("password",password);c1.setMaxAge(30);c2.setMaxAge(30);response.addCookie(c1);response.addCookie(c2);%>goto https://blog.csdn.net/ag_nevergiveup/article/details/a.jsp

5. Problem Analysis

Cookie cannot pass Chinese characters,

To pass a value, use the following code:

String s = URLEncoder (String, encoding)

Encode and then pass the value;

The value must be similar:

String s = URLDecoder (String, encoding)

Decoded to obtain the value;

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.