简体   繁体   English

struts1中表单bean与表单动作的用途是什么?

[英]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 the ActionForm . <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 the ActionServlet . <action>告诉 Struts 从ActionServlet调用哪个 class 。 Only the path and type are required entries.只有pathtype是必填项。 The type tells Struts which Action class to invoke when a URL with the model of the path 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 by ActionServlet , it must extend the class org.apache.struts.action.Action (see Listing 3).为了在<action-mappings>部分中输入 class 并由ActionServlet调用,它必须扩展 class org.apache.struts.action.Action The ActionServlet will execute the perform() method of the Action 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 and ActionForm objects will contain information found in the struts-config.xml <action-mappings> and <form-beans> sections. ActionMappingActionForm对象将包含在struts-config.xml <action-mappings><form-beans>部分中找到的信息。 The HttpServletRequest and HttpServletResponse objects are from the servlet. HttpServletRequestHttpServletResponse对象来自 servlet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM