spring mvc: 靜態資源/文件配置


靜態文件不用再放web-info 下面了,放在webapp/ 下面就行了(靜態文件放web-inf下你在jsp都無法引用~  注意一下所有js、css包括報表文件~ 配置文件等等等~  不要放在web-info下~)

WEB-INF只能內部訪問,外面是怎么都訪問不了的

看配置,如圖:

 

java代碼,WebController.java,靜態資源pages/final.html

WebController.java

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class WebController {

	
	@RequestMapping(value="/index", method = RequestMethod.GET)
	public String index()
	{
		return "index";
		
	}
	
	@RequestMapping(value="/staticPage", method = RequestMethod.GET)
	public String redirect()
	{
		return "redirect:/pages/final.html";
		
	}
}

  

靜態資源: webapp/page/final.html下

xml配置

在xxx-servlet.xml下面添加靜態目錄配置

<!-- 默認的注解映射的支持 -->
<mvc:annotation-driven /> 
<!-- 靜態資源 -->
<mvc:resources mapping="/pages/**" location="/pages/"/>

  

訪問地址: url/項目地址(hello)/index

訪問地址: url/項目地址(hello)/pages/final.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM