ServletUtil
Origin
Initially, Servlet-related tools were not considered within Hutool’s encapsulation scope. However, many people later requested a Servlet Cookie tool, so I decided to create ServletUtil. This tool’s usage scope is not limited to just Cookies, but also includes parameters and more.
In fact, the earliest Servlet encapsulation originated from the author’s MVC framework: Hulu. This MVC framework provided a layer of encapsulation for Servlet, making request handling more convenient. Therefore, Hutool encapsulates the methods in the Request and Response classes of Hulu here.
Usage
Add Dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<!-- This package is generally provided by the Servlet container -->
<scope>provided</scope>
</dependency>Methods
getParamMapobtains all request parameters.fillBeanconverts request parameters into a Bean.getClientIPobtains the client IP, supporting retrieval from Nginx header information or custom header information retrieval locations.getHeaderandgetHeaderIgnoreCaseobtain information from the request header.isIEchecks if the client browser is IE.isMultipartchecks if the form is of Multipart type, which is used for file uploads.getCookieobtains the specified Cookie.readCookieMapencapsulates cookies into a Map.addCookiesets the Cookie to be returned to the client.writereturns data to the client.setHeadersets the response header.