我们在进行springMVC开发时,必定会在jsp页面引入js文件、img文件和css文件。大多数人会将这些分类存放在WebRoot文件下新建的文件夹下面。同时,会在web.xml文件中配置拦截所有请求。这样就造成了页面无法访问到js、img和css文件夹中的文件了。
在SpringMVC中可以利用
下面是,我写的一个demo。
先看看其它文件。
web.xml(这个文件写好后几乎不用再进行修改了):
< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
先看显示图片的:img.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
你好SpringMVC!!!
显示一张图片
