When the jsp that is jumped to after the struts2 action is executed is displayed, the css does not work. Take the project where I am having problems as an example: The actions are as follows: Copy code The code is as follows:<action name="listUser" class="listUserAction"> <result>/users/userList.jsp</result> </action> ( Note : The function of listUser is to find all users and then display them in userList.jsp under users. Since spring is used, the "listUserAction" here is the name configured in applicationContext.xml) The css settings in userList.jsp are as follows : Copy code The code is as follows:<link href="../css/style.css" rel="stylesheet" type="text/css" /> ( Note : The directory hierarchy is like this, there are users and css folders under WebRoot, so if the jsp under users wants to call style.css, it needs to ../ go to the root directory and then find the css folder) However, when the program jumps to /users/userList.jsp after successfully executing from listUser, /css/style.css does not work. If jsp is displayed directly in the address bar, it can be displayed normally. The method found on the Internet says to use an absolute path for css : Copy code The code is as follows:<link href="http://blog.163.com/<%=request.getContextPath%>/css/style.css" rel="stylesheet" type="text/css" /> But this will have an obvious disadvantage, which is that the portability will be poor. Try to change result to <result>userList.jsp</result>, and then put jsp in the root directory, then there will be no such problem. At this time, the cause of the problem is almost known, that is, action is in the root directory. You can see it from the address bar when running the program, that is, the namespace is in the root directory, and then "../css/style.css" will naturally not be found. Once you understand the problem, the solution will be easy to find. Find the package where listUser is configured and add namespace="/users". This is the time Copy code The code is as follows:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="users" extends="struts-default" namespace="/users"> ...... <action name="listUser" class="listUserAction"> <result>/users/userList.jsp</result> </action> ...... </package> </strusts> Then restart the server, OK, it displays normally! At the same time, we can also see that there is an additional "/users" before the action in the address bar, and when jumping to the connected video, it is also "/users/userList.jsp", which keeps it consistent and solves the problem. |
<<: Let's talk in detail about the direction of slow SQL optimization in MySQL
Preface: Docker is an open source application con...
The players we see on the web pages are nothing m...
Table of contents 1. Download MySQL 1.1 Download ...
System environment: Redis version: 6.0.8 Docker v...
The accessibility of web pages seems to be somethi...
<br />In order to manage the vehicles enteri...
@vue+echarts realizes the flow effect of China ma...
Use the Vue-Cropper component to upload avatars. ...
1. Introduction to Nginx Nginx is a web server th...
Preface The MySQL slow query log is a type of log...
This article shares the MySQL 5.7.18 MSI installa...
Installation Environment Centos Environment Depen...
The default database of CentOS7 is mariadb, but m...
A few days ago, I saw an example written by @Kyle...
We better start paying attention, because HTML Po...