[英]How to add a import file with JS and CSS on a Spring MVC 4 and HTML5 application?
In my Spring MVC 4 application, I have WEB-INF/html/include/imports.html
file that has all the JavaScript and CSS, I should need throughout the application. 在我的Spring MVC 4应用程序中,我具有
WEB-INF/html/include/imports.html
所有JavaScript和CSS的WEB-INF/html/include/imports.html
文件,我在整个应用程序中都需要此文件。
The author of this HTML Imports article suggests the use of a link tag on my HTML5 pages, like: HTML Imports文章的作者建议在我的HTML5页面上使用链接标记,例如:
<link rel="import" href="include/imports.html" />
Where, on each page I use this tag, I'd need to adjust the relative path. 在每个使用此标记的页面上,我需要调整相对路径。 So far, no news.
到目前为止,还没有消息。 I'm used to doing it on JSP.
我习惯在JSP上执行此操作。
So, I have this very simple login page, mapped on my controller as: 因此,我有一个非常简单的登录页面,在我的控制器上映射为:
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage() {
return "login";
}
But whenever I try to load this login page, I get a console output of: 但是,每当我尝试加载此登录页面时,都会得到以下控制台输出:
Apr 06, 2016 8:19:30 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/hrm/include/imports.html] in DispatcherServlet with name 'dispatcher'
On Chrome's Developer Tools, I get this, saying it failed load the resource. 在Chrome的开发人员工具上,我明白了这一点,说它无法加载资源。
The WEB-INF structure is: WEB-INF结构为:
I don't really need this particular file mapped on my any controller, but I need it to be loaded by my pages. 我确实不需要在任何控制器上映射此特定文件,但是我需要由页面加载它。
What am I missing here? 我在这里想念什么?
您可以将文件imports.html
放在静态资源所在的位置,在这种情况下,您不需要Controller
的专用映射,浏览器将能够下载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.