[英]What is the use for form beans vs form action in struts1?
If form bean is used to store the variables of the JSP form connected via action="submitDetailForm"
for example then what are ActionForm
s for?例如,如果表单 bean 用于存储通过action="submitDetailForm"
连接的 JSP 表单的变量,那么ActionForm
的用途是什么?
Whats confusing about the app that I am working on is that it has forms that are actual beans but there's a bean folder that parses the request result.我正在开发的应用程序令人困惑的是它有 forms 是实际的 bean,但有一个解析请求结果的 bean 文件夹。
Forms are mapped to the action. Forms 映射到动作。 It doesn't matter which folder they belong.它们属于哪个文件夹并不重要。 Sometmes classes for form beans are in the same folder as action beans, sometimes form beans are in the separate folder.有时表单 bean 的类与操作 bean 位于同一文件夹中,有时表单 bean 位于单独的文件夹中。 Which folder is used cyou an find in struts-config.xml
.使用哪个文件夹可以在struts-config.xml
中找到。
Everything becomes clear if you read Struts struts-config.xml action-mapping explained :如果您阅读Struts struts-config.xml 动作映射说明,一切都会变得清晰:
The
type
attribute of the<form-bean>
is used to enter FQCN of the bean class that would probably extend theActionForm
.<form-bean>
的type
属性用于输入可能会扩展ActionForm
的 bean class 的 FQCN。 It's needed by Struts to be able to instantiate a bean when required. Struts 需要它能够在需要时实例化 bean。
You can also read this article for quick overview of the framework Struts :您还可以阅读本文以快速了解Struts框架:
The
struts-config.xml
file can have several sections.struts-config.xml
文件可以有几个部分。 The first section we will look at is the<action-mappings>
section.我们要看的第一部分是<action-mappings>
部分。<action>
tells Struts which class to invoke from theActionServlet
.<action>
告诉 Struts 从ActionServlet
调用哪个 class 。 Only thepath
andtype
are required entries.只有path
和type
是必填项。 Thetype
tells Struts whichAction
class to invoke when a URL with the model of thepath
is found.该type
告诉 Struts 当找到path
的 model 的 URL 时调用哪个Action
class。In order for a class to be entered in the
<action-mappings>
section and to be invoked byActionServlet
, it must extend the classorg.apache.struts.action.Action
(see Listing 3).为了在<action-mappings>
部分中输入 class 并由ActionServlet
调用,它必须扩展 classorg.apache.struts.action.Action
。 TheActionServlet
will execute theperform()
method of theAction
object.ActionServlet
将执行Action
object 的perform()
方法。 The perform method looks like this: perform 方法如下所示:public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
The
ActionMapping
andActionForm
objects will contain information found in thestruts-config.xml
<action-mappings>
and<form-beans>
sections.ActionMapping
和ActionForm
对象将包含在struts-config.xml
<action-mappings>
和<form-beans>
部分中找到的信息。 TheHttpServletRequest
andHttpServletResponse
objects are from the servlet.HttpServletRequest
和HttpServletResponse
对象来自 servlet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.