[英]Spring MVC controller using @RequestParam with Apache tile 2
I am have the following configuration for my Spring MVC + Apache tile 2 project. 我的Spring MVC + Apache tile 2项目具有以下配置。
The Tile configuration
Tile配置
<definition name="test1" extends="mymain"> <put-attribute name="main"> <definition template="/WEB-INF/views/tiles/template/generictemplate.jsp"> <put-attribute name="headerstyle" value="./resources/css/header.css" type="string" /> <put-attribute name="genericcontent" value="/WEB-INF/views/tiles/test.jsp" /> </definition> </put-attribute> </definition> <definition name="test2" extends="mymain"> <put-attribute name="main"> <definition template="/WEB-INF/views/tiles/template/generictemplate.jsp"> <put-attribute name="headerstyle" value="./resources/css/header.css" type="string" /> <put-attribute name="genericcontent" value="/WEB-INF/views/tiles/test.jsp" /> </definition> </put-attribute> </definition>
The controller
控制器
@RequestMapping(value="/test1", method=RequestMethod.GET) public String test1(@RequestParam(value="id", required=true) String id){ return "test1"; } @RequestMapping(value="/test2", method=RequestMethod.GET) public String test2(){ return "test2"; }
The view generictemplate.jsp
视图generictemplate.jsp
<%@ include file="include.jsp" %> <tiles:importAttribute name="headerstyle" /> <link href="${headerstyle}" rel="stylesheet" type="text/css" /> <div role="main" class="main clearfix"> <section class="generic"> <div class="post"> <tiles:insertAttribute name="genericcontent"/> </div> </section> <!-- end main --> </div>
My problem is When i am calling test2 (without parameter), the header.css can be read.
我的问题是,当我调用test2(不带参数)时,可以读取header.css。 But when test1 is called, I am getting
404 Not Found for header.css.
但是,当调用test1时,header.css却显示404 Not Found 。 I noticed that view is trying to access the css with path of
我注意到该视图正在尝试使用以下路径访问CSS
http://localhost:8080/myproject/test1/resources/css/header.cssinstead of
http://localhost:8080/myproject/resources/css/header.csswhen test1 is calling.http:// localhost:8080 / myproject / resources / css / header.css
Thank. 谢谢。
This is because the css is being loaded relative to the current URL. 这是因为css是相对于当前URL加载的。 For test1 you have a param which adds a slash after test1.
对于test1,您有一个参数,它在test1之后添加一个斜杠。 Where as test2 doesn't have the param, so its relative to the parent directory.
由于test2没有参数,因此它相对于父目录。
You could try using absolute paths for the css. 您可以尝试对CSS使用绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.