java 将模型属性分配给jsp Spring MVC中的java变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32138856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
assigning model attribute to java variable in jsp Spring MVC
提问by user3378974
I want to assign model object to java variable in jsp page for spring mvc application. Can you please help me on how to do that. Like, I am sending below variable to view
我想将模型对象分配给 spring mvc 应用程序的 jsp 页面中的 java 变量。你能帮我看看如何做到这一点。就像,我正在发送下面的变量来查看
model.addAttribute("inCount", 15);
Then i want something like below,
然后我想要像下面这样的东西,
<% int rowCount = inCount;
%>
May be in jstl, there is a way on writing this kind of java code. Can you please guide me. Thanks in advance
可能在jstl中,有一种写这种java代码的方法。你能指导我吗。提前致谢
回答by sanjay
try this
试试这个
int rowcount = (int) request.getAttribute("inCount");
**OR**
int rowcount = Integer.parseInt(request.getAttribute("inCount"));
回答by JorgeBPrado
If you want to show the value of the variable 'inCount' you can use c:out
如果要显示变量“inCount”的值,可以使用 c:out
So if you write :
所以如果你写:
<c:out value="${inCount}"/>
it will show the value of 'inCount'.
它将显示“inCount”的值。
Otherwise, if what you want is to reassign the variable inCount of your scope to a new variable you should use c:set
否则,如果您想要将作用域的变量 inCount 重新分配给新变量,则应使用 c:set
<c:set var="rowCount" scope="session" value="${inCount}"/>
You can have more info in:
您可以在以下位置获得更多信息:
http://www.tutorialspoint.com/jsp/jstl_core_set_tag.htmhttp://www.tutorialspoint.com/jsp/jstl_core_out_tag.htm
http://www.tutorialspoint.com/jsp/jstl_core_set_tag.htm http://www.tutorialspoint.com/jsp/jstl_core_out_tag.htm