In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use Filter filter to access getSession ()". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Access to getSession () in Filter filter to convert public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; User user = (User) req.getSession (). GetAttribute ("user");} request.getSession ()
In JavaWeb projects, request.getSession () is typically used to store the current user object in session or to get the current user object from session.
It is divided into two writing methods: no reference and no reference.
1. No parameter: request.getSession ()
Get the session from the current request. If you cannot get the session, a session will be created automatically and the newly created session; will be returned. If so, the session will be returned.
two。 Reference: request.getSession (boolean var1)
Request.getSession (true)
This method is the same as when there is no participation, except that an additional true parameter is added, which explicitly tells it to automatically create a session when it cannot get it.
Request.getSession (false)
The difference between this method and the above two is that when the session is not available, the session is not automatically created, but the null is returned.
Various application scenarios:
If you want to store information in session, use request.getSession ()
If you want to get the information in session, use request.getsession (false), and determine whether the session variable is null after getting it, and then proceed to the next step.
That's all for "how to access getSession () in the Filter filter". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.