Tomcat Redis session Github address.
Download the Commons-pool2-2.2.jar,jedis-2.5.2.jar,tomcat-redis-session-manager-2.0.0.jar three packages and put them under the Lib directory under the Tomcat directory.
Modify the Context.xml file under Tomcat's Conf directory.
Insert the following code in the context.
| The code is as follows |
Copy Code |
|
<valve classname= "Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>
<manager classname= "Com.orangefunction.tomcat.redissessions.RedisSessionManager"
host= "localhost"
Port= "6389"
database= "0"
Maxinactiveinterval= "60"
/> |
You can view the configuration of GitHub in a more detailed way.
This configures a simple environment that uses Redis to store sessions, and can take the same configuration for clusters.
To test the servlet:
| The code is as follows |
Copy Code |
|
@WebServlet (urlpatterns = "/myhttp")
public class Myhttpservlet extends HttpServlet {
@Override
protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
Get session
HttpSession HttpSession = request.getsession;
Httpsession.setattribute ("name", "name");
Set to 0 never expires
Httpsession.setmaxinactiveinterval (1000);
Make httpserssion Invalid
Httpsession.invalidate;
System.out.println (Httpsession.getid);
Response.getWriter.print ("http");
}
}
|
Start Tomcat, access http://localhost:8080/myhttp can be seen under Redis
The proof environment has been configured successfully and can be used.