使用 Java Bean 和 JSP 的属性填充 HTML 表单?
我有一个带有这样的表单的网页:
<html>
<head>
...
</head>
<body>
<form id="form4" name="form4" method="post" action="Receive.jsp">
<input name="inputField1" type="text"/>
...
<input type="submit" value="Send"/>
</form>
</body>
</html>
然后在我的 Receive.jsp
中我使用:
<jsp:useBean id="form4" class="control.FormBean4" scope="session"/>
<jsp:setProperty name="form4" property="*"/>
将表单中的所有输入数据获取到 Bean 中,然后我用它做一些事情。现在,我想要做的是将 Bean 中的数据重定向到另一个包含另一个表单的 JSP,并使用我的 Bean 中的属性填写该表单的输入字段。我的问题是是否有某种方法可以自动填写表单,如
但向后?
我已经尝试过
,但它显然不起作用(我在 JSP 参考中的某处读到这是无效的) ,所以我想知道你是否知道一些方法来做到这一点,因为我有不止一个表单,每个表单都有一堆字段,我想保存一一设置值的所有工作。
我仍然是 JSP 的新手,对 JSTL 或任何框架(如 Struts)了解不多,任何帮助将不胜感激。
I have webpage with a form like this:
<html>
<head>
...
</head>
<body>
<form id="form4" name="form4" method="post" action="Receive.jsp">
<input name="inputField1" type="text"/>
...
<input type="submit" value="Send"/>
</form>
</body>
</html>
Then in my Receive.jsp
I use:
<jsp:useBean id="form4" class="control.FormBean4" scope="session"/>
<jsp:setProperty name="form4" property="*"/>
To get all the input data from the form into a Bean, then I do some stuff with it. Now, what I want to do is to redirect the data from the Bean into another JSP with another form in it and fill out the input fields of that form with the properties from my Bean. My question is if there is some way to automatically fill the form like <jsp:setProperty name="form4" property="*"/>
but backwards?
I already tried <jsp:getProperty name="form4" property="*"/>
, but it obviously didn't work (I read somewhere in the JSP reference that this is not valid), so I'm wondering if you know some way to do this, because I have more than just one form each one with a bunch of fields and I'd like to save all the work of setting the values one by one.
I'm still a newbie in JSP and don't really know much about the JSTL or any frameworks like Struts, any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否您需要自己做,或者使用基于 JSP/Servlet 的 MVC 框架,如 JSF、Struts、Spring-MVC 等。
要自己做:
使用例如 JSF 来做:
(这反过来又立即最小化
和所有 Servlet 代码样板)No. You'd need to either do it yourself, or to head to a JSP/Servlet based MVC framework like JSF, Struts, Spring-MVC, etc.
To do it yourself:
To do it with for example JSF:
(which in turn also immediately minimizes the
<jsp:useBean>
and all Servlet code boilerplate)