【发布时间】:2016-12-30 20:38:44
【问题描述】:
在网络应用程序(在 Eclipse 上开发)中,我希望用户在浏览器中利用 url。 Web app基于java spring mvc,控制器返回html页面。 所有 html 页面都在 WebContent/WEB-INF/views 文件夹中。所有 css\javacript\images 都在 WebContent/resources/{css\javacript\images} 文件夹中。
以下是此网络应用应访问的网址
- localhost:8080/Project/home - 用于 home.html
- localhost:8080/Project/about - for about.html
- localhost:8080/Project/vendor - 用于vendor.html(点击后将显示所有供应商详细信息列表)
现在我想为供应商实现类别过滤器
- localhost:8080/Project/vendor/med - 用于 vendor.html(使用 js 重用页面以仅显示医疗供应商详细信息列表)
- localhost:8080/Project/vendor/army - 用于 vendor.html(使用 js 重用页面以仅显示军队供应商详细信息列表)
- localhost:8080/Project/vendor/other - 用于 vendor.html(使用 js 重用页面以仅显示其他供应商详细信息列表)
在 vendor.html 上进一步(可能是 {all, med, Army, other} 供应商)点击名称链接并将网址设为
localhost:8080/Project/vendor/med/vendor_XX 显示所选 vendor_XX 的完整信息 -(在 vendor_XX.html 中编码)
所有提交都是GET类型
home/about/vendor_XX.html
<html>
<link rel="stylesheet" href="resources/css/mystyle.css" type="text/css" />
<a href="home">Home</a>
<a href="vendor">Vendor</a>
<a href="about">About</a>
<a href="vendor/med">Medical</a>
<a href="vendor/army">Army</a>
<a href="vendor/other">Other</a>
// and other non relevant stuff
</html>
vendor.html
<html>
<link rel="stylesheet" href="resources/css/mystyle.css" type="text/css" />
<a href="home">Home</a>
<a href="vendor">Vendor</a>
<a href="about">About</a>
<a href="vendor/med">Medical</a>
<a href="vendor/army">Army</a>
<a href="vendor/other">Other</a>
// generating below 3 line dynamically with js
<a href="vendor/med/vendor_xx">Vendor_XX</a>
<a href="vendor/med/vendor_yy">Vendor_YY</a>
<a href="vendor/other/vendor_zz">Vendor_ZZ</a>
// and other non relevant stuff
</html>
我的控制器
@Controller
public class AppController {
@RequestMapping(value = "home", method = RequestMethod.GET)
public String home() {
return "home";
}
@RequestMapping(value = "vendor", method = RequestMethod.GET)
public String vendor() {
return "vendor";
}
@RequestMapping(value = "vendor/med", method = RequestMethod.GET)
public String vendorMed() {
return "vendor";
}
@RequestMapping(value = "vendor/army", method = RequestMethod.GET)
public String vendorArmy() {
return "vendor";
}
@RequestMapping(value = "vendor/med/vendor_xx", method = RequestMethod.GET)
public String vendorMedXX() {
return "vendor_xx";
}
//all sample urls are given
}
Resources 文件夹被添加到项目的构建路径中
localhost:8080/Project/vendor/med/vendor_XX 将上面的 url 视为 localhost:8080/Project/level_1/level_2/level_3
问题
1) - 除了 level_1 之外的所有 url 都没有找到 css。
level_2 url 需要 css 导入为<link rel="stylesheet" href="../resources/css/mystyle.css" type="text/css" />
level_3 url需要css导入为<link rel="stylesheet" href="../../resources/css/mystyle.css" type="text/css" />
问题 1 - 为什么不从资源中加载 css。我错过了什么吗?
2) - 如果我点击
<a href="home">Home</a>
从 level_1/level_2 vendor.html,它被定向到 level_1/home。因此在控制器请求映射中找不到。
问题 2 - 我们如何重定向到 localhost:8080/Project/home ?
【问题讨论】:
标签: java spring-mvc url