In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use servlet forwarding and redirection". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use servlet forwarding and redirection.
When we learn servlet, we have two very important concepts: forwarding and redirection.
After the teacher finished the lecture, he helped us summarize their respective characteristics:
Redirect:
1. The address bar has changed
two。 Redirect can access resources of other sites (servers)
3. Redirects are two requests. You cannot use request objects to share data
Forward:
1. The forwarding address bar path remains unchanged
two。 Forwarding can only access resources under the current server
3. Forwarding is a request, and you can use request objects to share data
But are you still confused after listening to it? What on earth are these two?
Examples in life
Retweet-you ask me to borrow money, I have no money, but I can help you find someone to borrow money. It's up to me to help you find someone to borrow money. Here I mean the web server, such as tomcat!
Redirect-you asked me to borrow money, and I said there was no money to get out of here, so you had to slip away. Then go and borrow it from someone else. Here you mean the browser.
Examples in the project
Retweet: after a successful login, jump to the interface where the login is successful, such as home.jsp. I said to tomcat, "can you take me to the system home page after I have successfully logged in?" Tomcat said, "No problem, I'll help you!" / * Administrator Login * @ return * / @ RequestMapping ("/ login") public String login (Admins admin, HttpServletRequest request, HttpSession session) {if (adminService.checkUser (admin.getUsername (), admin.getPassword () {session.setAttribute ("username", admin.getUsername ());} return "/ admin/home.jsp" } Redirect: the user logs out of the system and redirects to the login interface. I said to tomcat, "could you log in for me again after I quit?" Tomcat said, "get out of the way and log in yourself. I'm not helping you!"
/ / exit @ RequestMapping ("/ logout") public String list (HttpSession session) throws Exception {session.invalidate (); / / redirect to index.jsp return "redirect:/index.jsp";} Summary: forwarding can continue to access tomcat server resources, such as jsp. The redirection must send another request to servlet (Controller). Thank you for reading, the above is the content of "how to use servlet forwarding and redirection". After the study of this article, I believe you have a deeper understanding of how to use servlet forwarding and redirection, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.