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
First look at the code and effect↓ <style> ...
In tomcat, jsp is not garbled, but html Chinese i...
Table of contents 1. Phenomenon 2. Solution 3. Su...
I recently encountered a bug where I was trying t...
Table of contents Preface Basic Usage grammar Err...
MySQL 8.0.20 installation and configuration super...
Table of contents Preface Why does limit deep pag...
A docker container state transition diagram Secon...
Table of contents 1. Enter a value and return its...
Install mysql5.7 under win, for your reference, t...
Using the official MySQL image requires some modi...
Table of contents Previous words Usage scenarios ...
Preface This article mainly introduces the releva...
Table of contents el-scrollbar scroll bar el-uplo...
First way: skip-grant-tables: Very useful mysql s...