解析静态资源地址显示$%7BpageContext.request.contextPath%7D

1.问题:

${pageContext.request.contextPath}被解析成$%7BpageContext.request.contextPath%7D
Java项目中,当你在jsp中使用${pageContext.request.contextPath}来获取相对路径。但是,发布项目后,访问页面时,${pageContext.request.contextPath}被解析成$%7BpageContext.request.contextPath%7D

解决方案:查看web.xml中头文件web-app的版本,如果低于2.4,修改web-app的版本即可正常获取相对路径,页面正常显示显示。

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

server { listen 8001; server_name localhost; # 前端1的dist目录 root /jjkj/web/local1/dist; index index.html; # 错误页面 error_page 404 /404.html; error_page 500 502 503 504 /50x.html; # 静态资源缓存策略 location ~* \.(?:js|css|png|jpg|jpeg|gif|ico|svg|woff2|webp)$ { # 带哈希值的文件长期缓存 if ($request_uri ~* "(\.[0-9a-f]{8,32}\.(?:js|css))$") { expires 1y; add_header Cache-Control "public, immutable, max-age=31536000"; } # 不带哈希值的文件中等缓存 if ($request_uri !~* "(\.[0-9a-f]{8,32}\.(?:js|css))$") { expires 7d; add_header Cache-Control "public, max-age=604800"; } try_files $uri =404; access_log off; # 减少日志 } # HTML文件不缓存 location ~* \.(?:html)$ { expires -1; add_header Cache-Control "no-store, no-cache, must-revalidate"; } # API请求转发到后端1 location /yaxt-boot/ { proxy_pass http://backend1; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # 超时设置 proxy_connect_timeout 60s; proxy_read_timeout 60s; proxy_send_timeout 60s; proxy_buffer_size 4k; proxy_buffers 8 16k; proxy_busy_buffers_size 24k; } # WebSocket支持 location /ws/ { proxy_pass http://backend1; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; } # SPA路由处理 location / { try_files $uri $uri/ /index.html; # 添加安全头 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "no-referrer-when-downgrade" always; } # 禁止访问隐藏文件 location ~ /\. { deny all; access_log off; log_not_found off; } # 健康检查端点 location /healthz { access_log off; return 200 'OK'; add_header Content-Type text/plain; } } 改成这样还是报404
最新发布
08-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值