本文介绍了使用Servlet和JSP将表单参数绑定到bean - 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用没有框架的Servlet和JSP来研究我的SCWCD。我有一个简单的表单,我希望参数自动绑定到bean。如果没有编写绑定代码或使用框架,这是否可行?
I am using Servlet and JSP without a framework to study for my SCWCD. I have a simple form that I want the parameters to bind to a bean automatically. Is this possible without writing binding code or using a framework?
谢谢
推荐答案
不,不是。你应该使用一些框架,我认为这是一个过度杀伤。
No, it isn't. You should use some framework, which I guess would be an overkill.
所以你可以做的是迭代 request.getParameterMap()
键并使用相应的字段名称(通过反射)将值设置为object
So what you can do, is iterate request.getParameterMap()
keys and set the values to object with the corresponding field names (via reflection)
这篇关于使用Servlet和JSP将表单参数绑定到bean - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!