Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将@modeldattribute传递给href-Spring-MVC_Spring_Model View Controller - Fatal编程技术网

将@modeldattribute传递给href-Spring-MVC

将@modeldattribute传递给href-Spring-MVC,spring,model-view-controller,Spring,Model View Controller,我试图通过@modeldattribute从服务器端传递计算出的URL,有时html中的href属性(我在其中分配这个@modeldattribute)看起来是空的,需要执行多次ctrl-f5以最终设置URL 我的控制器有如下功能: @Controller .... String calculatedURL = calculateURL(request, user); if(StringUtils.isBlank(calculatedURL)){ throw new Exception("Err

我试图通过@modeldattribute从服务器端传递计算出的URL,有时html中的href属性(我在其中分配这个@modeldattribute)看起来是空的,需要执行多次ctrl-f5以最终设置URL

我的控制器有如下功能:

@Controller
....
String calculatedURL = calculateURL(request, user);
if(StringUtils.isBlank(calculatedURL)){
throw new Exception("Error calculating URL");
}
model.addAttribute("calculatedURL",calculatedURL);
return "myPage";
在我的JSP中:

<a href="${calculatedURL}">myLink</a>

问题是,有时此href值为“”。 我试图在我的控制器中评估calculatedURL是null还是空白,如果是,则抛出异常。这永远不会发生,calculatedURL始终随值传递

提前谢谢,我的英语很抱歉


David。

很难预测方法的行为,但它是否需要一些不绑定到请求的状态?你能提供更多关于这个方法的信息吗?嗨,迪奥戈,谢谢你的回复。我在返回页面之前添加了这个控件,但它从未发生过,因此calculatedURL allways具有价值。