靜態文件不用再放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