java spring js文件,由于路径差异java,spring mvc,velocity找不到JS / CSS文件

I have this directory structure:

webapp

- resources

- custom.js

- base.css

- WEB-INF

- views

- layout.vm

- top.vm

- footer.vm

- index.vm

- FolderA

- restricted.vm

My layout.vm is:

#parse('top.vm')

$screen_content

#parse('footer.vm')

My top.vm consists include these JS and CSS files:

Now when my I access http://www.example.com:8080/index page, I see the JS and CSS files getting found.

But when I visit http://www.example.com:8080/FolderA/restricted, JS and CSS files are not found. It works when in top I change it

But then the index page is broken.

I am using spring controllers to return the appropriate views.

For e.g. The following returns the index page:

@RequestMapping(value = "/", method = RequestMethod.GET)

public String home(Model model) {

return "index";

}

and this returns the restricted view:

@Controller

@RequestMapping(value = "/FolderA")

public class SomeController {

@RequestMapping(value = "", method = RequestMethod.GET)

public String secured(Model model) {

return "FolderA/restricted";

}

Any suggestions as to how I can fix this issue?

On a side note, I was facing this issue when using regular jsp files as well, but I managed to fix it using . I dont know how this can solved in velocity.

解决方案

thats because the resources you have declared are relative to the url used for accessing the view.

You have to change all the static resource urls to absolute

You can do this using tag

change from this

to

">

this should generate something like this in the HTML

">

Note

But for this to work you should add

%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> to your jsp

and include jst tag library into the webapp

Edit------

For the paths referred inside in JS and CSS files , there is a work around.Use base tag to

define the absolute path tags in the HTML need to use

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值