【发布时间】:2014-04-11 06:36:51
【问题描述】:
我正在开发 Spring MVC 控制器项目。我有一个 JSP 页面,其中包含某些表单,人们会在其中键入某些条目,然后按提交按钮。
现在下面是我的代码库 - 只要我在浏览器上点击此网址 -
http://localhost:8080/testweb/testOperation
如果我放置一个断点,它会自动转到下面的方法,然后它会在浏览器上显示我的testOperation jsp 页面,它工作正常。
@RequestMapping(value = "testOperation", method = RequestMethod.GET)
public Map<String, String> testOperation() {
final Map<String, String> model = new LinkedHashMap<String, String>();
return model;
}
现在我要做的是 - 假设在下面的方法中,一旦呼叫到来,我将从呼叫到来的标头中提取 IP 地址,如果 IP 地址不匹配,那么我会喜欢显示错误 JSP 页面,但如果 IP 地址匹配,那么我将显示 testOperation jsp 页面。
@RequestMapping(value = "testOperation", method = RequestMethod.GET)
public Map<String, String> testOperation(final HttpServletRequest request) {
final Map<String, String> model = new LinkedHashMap<String, String>();
//is client behind something?
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
if(ipAddress.equals("something_here")) {
// then load testOperation jsp page
} else {
// otherwise load some error jsp page
}
return model;
}
这有可能以某种方式做到吗?
【问题讨论】:
标签: java spring jsp spring-mvc annotations