如何将变量从servlet传递到jsp页面? [英] How to pass variable from a servlet to a jsp page?
问题描述
我有一个servlet(前控制器),它可以分析请求,准备一些必要的数据(模型),然后将其传递给要呈现的jsp.
I have a servlet (front-controller), which analyse the request, prepare some necessary data (model) and then should pass it to the jsp to be rendered.
如何将数据从servlet传递到jsp? (我希望可以在request
对象的参数映射中添加新参数,但是该映射不可修改.)
How should I pass the data from servlet to jsp? (I hoped that it was possible to add new parameters to parameters map in the request
object, but that map is unmodifiable).
我可以向request
添加属性,但是我不知道如何从jsp中检索它们.
I can add attributes to the request
but I don't know how to retrieve them from the jsp.
所有数据都应在请求范围内.正确的方法是什么?
All the data should be in the request scope. What's the correct way?
推荐答案
我可以向请求中添加属性,但是我不知道如何从jsp中检索属性.
您无需专门检索"它们,只需引用它们即可
I can add attributes to the request but I don't know how to retrieve them from the jsp.
You don't need to specifically 'retrieve' them, just referring them works
request.setAttribute("titleAttribute", "kittens are fuzzy");
然后
Title here: ${titleAttribute}
这篇关于如何将变量从servlet传递到jsp页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!