javaee springMVC 放行静态资源

spring配置文件

在配置文件中添加配置

<mvc:resources mapping="/static/**" location="/static/" />

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
      <!-- 1. 配置  需要扫描的控制层在哪个包  -->
    <context:component-scan base-package="com.test"></context:component-scan>

    <!-- 2 配置 视图解析器 中的 前缀和后缀  -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 设置前缀  -->
        <property name="prefix" value="/WEB-INF/"/>
        <!-- 设置后缀 -->

        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 开启注解驱动
      注册了两个数据转换的注解@NumberFormatannotation支持,@DateTimeFormat
      json相关的。。
    -->
    <mvc:annotation-driven></mvc:annotation-driven>

    <!-- 放行静态资源
        location:静态资源的真实路径
        mapping:访问路径(可以自定义)
        放行static文件夹下的所有的文件
     -->
    <mvc:resources mapping="/static/**" location="/static/" />


</beans>

jsp

html 复制代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<img src="static/images/timg.jpg" />
<h2>Hello World!</h2>
<c:if test="${loginUser==null}">
    请<a href="users/loginUi">登录</a>
</c:if>
<c:if test="${loginUser!=null}">
    ${loginUser.uname},欢迎您!
</c:if>
</body>
</html>

结构

相关推荐
c***937711 分钟前
SpringBoot实现异步调用的方法
java·spring boot·spring
科研面壁者15 分钟前
SPSS——独立样本T检验
数据库·人工智能·机器学习·信息可视化·数据分析·spss·数据处理
云栈开源日记17 分钟前
Python 开发技术栈梳理:从数据库、爬虫到 Django 与机器学习
数据库·爬虫·python·学习·机器学习·django
青衫码上行18 分钟前
【Java Web学习 | 第15篇】jQuery(万字长文警告)
java·开发语言·前端·学习·jquery
凯子坚持 c1 小时前
Docker 容器实战:从镜像管理到私有仓库构建深度解析
java·docker·eureka
倔强的石头1061 小时前
openGauss数据库:从CentOS 7.9部署到实战验证
linux·数据库·centos
q***01652 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat
4***14903 小时前
MySQL调试技巧与工具
数据库·mysql
Arva .3 小时前
如何监控并优化慢 SQL?
数据库·sql
f***68604 小时前
【SpringBoot篇】详解Bean的管理(获取bean,bean的作用域,第三方bean)
java·spring boot·后端