javaee springMVC 放行静态资源

spring配置文件

在配置文件中添加配置


<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">
      
    <context:component-scan base-package="com.test">context:component-scan>

    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        <property name="prefix" value="/WEB-INF/"/>
        

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

    
    <mvc:annotation-driven>mvc:annotation-driven>

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


beans>

jsp

<%@ 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>

结构

javaee springMVC 放行静态资源_第1张图片

你可能感兴趣的:(Mac开发,java-ee,java,数据库)