我有以下配置,我没有在这里写下其他默认配置
弹簧servlet.xml中
/ WEB-INF /视图/ .JSP
<!-- Handle efficient GET requests for resources --> <mvc:resources mapping="/resources/**" location="resources/" /> <mvc:annotation-driven />
控制器类
@Controller public class TablesController { @Autowired private ReferenceTableService referenceTableService; @RequestMapping(value = "/tables/edit", method = RequestMethod.GET) public String ShowTables(ModelMap map, @RequestParam(value = "tn", required = false) String tableName) { return "tables"; }
jsp文件
<html lang="en"><head><meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"> <head> <!-- Font Awesome CSS -->
<link href="resources/css/font-awesome.min.css" rel="stylesheet"/>
</head> <body> Test </body> </html>
当我尝试在本地加载时:
http://localhost:9081/myapp/tables/edit
在资源下的静态文件中出现以下错误:您可以看到表已添加到上下文中
000000aa PageNotFound W org.springframework.web.servlet.DispatcherServlet noHandlerFound找不到带有URI的HTTP请求的映射[/myapp/tables/resources/css/font-awesome.min.css] in DispatcherServlet,名称为'application'
如果我将请求映射从 / tables / edit 更改为 / tables ,则资源正在完美加载。
以下是文件夹结构:
答案 0 :(得分:0)
更改
<link href="resources/css/font-awesome.min.css" rel="stylesheet"/>
到
<link href="/myapp/resources/css/font-awesome.min.css" rel="stylesheet"/>
/myapp
表示它将在根路径中检索css
,如果没有它,它将在相对路径中执行此操作。
答案 1 :(得分:0)
能够通过向css文件添加contextpath来解决这个问题,如下所示:
var clickFlag = false;
nodeEnter.append("text")
.attr("x", function(d) { return d.children || d._children ? -10 : 10; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.text(function(d) { return d.name; })
.style("fill-opacity", 1e-6)
.style("font-weight", function(d) { return d.father == undefined ? "":"bold";})
.style("font-size", function(d) { return d.father == undefined ? "":"14px";})
.on('click', function(d){
if(clickFlag){
tip.hide(d);
}else{
tip.show(d);
}
return clickFlag = !clickFlag;
})