Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Activation and passivation of Session, repeated submission of forms, use process of CAPTCHA

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

passivation

Serializing HttpSession objects to the hard disk. Generally passivation occurs when the server stops. When the server stops, the HttpSession objects will be serialized to the hard disk automatically. This is called passivation.

activation

Load the HttpSession object in the hard disk into memory. Generally, when the server starts, the HttpSession object in the hard disk will be automatically reloaded into memory. This process is called activation.

Passivation refers to writing objects in memory to hard disk,

A class that can be serialized to hard disk must implement the java.io.Serializable interface

All properties in this class also need to implement the java.io.Serializable interface

If the server has a large number of visits, then the server will have a large number of HttpSession objects.

But these objects are not all in an active state, but these inactive objects will also exist in memory.

This will take up a lot of memory, then we want to write these idle objects to the hard disk, in the user needs to use the session to load into memory.

You can add the following to the context.xml file

maxIdleSwap: refers to the maximum idle time of the session. After this time, the session will be automatically deactivated.

directory: directory passivated to hard disk

Session will be passivated into the tomcat server's work directory

Duplicate submission of forms

Form duplicate submission refers to multiple submissions of the same content for the same form.

The hazards of repeated form submission:

1. Repeated form submissions are duplicate data, which will increase the garbage data in the database.

2. Invisible increase in server pressure.

There are several situations in which forms are submitted repeatedly:

1. After the form is submitted successfully, the successful page is refreshed repeatedly.

Root cause of the problem:

We jump to the successful page in the form of forwarding used by Servlet, so the browser only sends a request during the whole process. When we refresh the successful page, we actually send the last request again, so it causes repeated submission.

Solution:

Instead of forwarding, redirect is used

The redirect made two requests and we refreshed again, refreshing the second request instead of the first.

2. On slower speeds, users hit the submit button multiple times.

Root cause of the problem:

The submit button of the form can be clicked multiple times

Solution:

Make the submit button of the form only clicked once, after which the button becomes unavailable.

_window.onload = function(){

//After clicking the submit button, make the button unavailable

//Get button object

var btn = document.getElementById("btn");

//bind a one-click response function to the button

btn.onclick = function(){

//Set button is unavailable

this.disabled = true;

//If the button is set to inactive, the form will not be submitted either

//we need to manually submit the form

this[xss_clean].submit();

};

};

3. After successfully submitting the request, click the Back button, but submit again without refreshing the page.

Root cause of the problem:

Server-side servlets cannot distinguish between two requests for duplicate content

Solution:

In Servlet, we need to check whether the form is a duplicate submission before processing the request.

Use token to solve this problem

Token means token.

The so-called token is that the server checks whether the token is correct before processing the user request. If the token is correct, the server processes the request normally. If the token is incorrect, the server does not process the request.

Our token is a one-time token that can only be used once.

Process:

1. Create a token that is unique and cannot be duplicated (UUID) and save the token on the server.

2. into the browser form.

3. When the browser submits the form, it submits the token along with it.

4. The server checks whether the token is valid before processing the request.

5. Destroy the token.

Captcha Usage Process

Most of the above work can be done with a jar package.

kaptcha-2.3.2

The Jar can:

1. A random string can be generated

2. String can be saved to session

3. You can convert a string into an image.

This kaptcha-2.3.2 is actually a Servlet, we can directly complete the above work by accessing the Servlet he provides us.

After importing the jar package, register servelt in the web.xml file.

< servlet>

< servlet-name >

kaptcha com.google.code.kaptcha.servlet.KaptchaServlet //Store the name of the attribute of the Captcha in the session kaptcha.session.key code kaptcha /code.jpg

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report