In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you what to do about the failure of css and js after struts2 jump, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
When you use the action of struts2 to jump to the jsp display after execution, the css in it does not work. Take the project that I have a problem with as an example:
Action is as follows:
/ users/userList.jsp
Note: the function of listUser is to find out all the users, and then give it to the userList.jsp under users to show it. Due to the use of spring, the "listUserAction" here is the name configured in applicationContext.xml)
The css settings in userList.jsp are as follows:
The code is as follows:
(note: the directory hierarchy is like this. There are users and css folders under WebRoot, so jsp under users needs.. / to the root directory to call style.css, and then find the css folder)
However, when the program jumps to / users/userList.jsp after the successful execution of listUser, / css/style.css does not work. If the jsp is displayed directly in the address bar, it can be displayed normally.
The method found on the Internet says that css uses an absolute path:
The code is as follows:
But there is an obvious drawback, that is, portability becomes worse.
Try to change result to userList.jsp, and then put jsp in the root directory will not have this problem, then the cause of the problem is almost known, that is, action is in the root directory, when running the program can be seen from the address bar, that is, the namespace is in the root directory, then ".. / css/style.css" naturally can not be found.
Once you understand the problem, it is not difficult to find a solution. Find the package where the configuration of listUser is located, and add the sentence namespace= "/ users". This is the time.
The code is as follows:
.
/ users/userList.jsp
.
Then restart the server, OK, and display normally! At the same time, we also see that there is a "/ users" in front of the action in the address bar, and the jump to the video is also "/ users/userList.jsp", so it is consistent and the problem is solved.
These are all the contents of the article "what to do when css and js fail after struts2 Jump". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.