13、说说struts吧

 


 



Below are some of the important Java Struts interview questions and answers gathered from various users.


What Are Struts?


Struts framework is a prerequisite for a professional web application. It is the framework that every web application developer should have in his or her toolbox. The Struts framework provides the scaffolding for the workings of a web application. Published standards and its proven design pattern will enable your application to have an expansible development pattern.


The core of the framework is a flexible control layer, adhering to standard technologies such as Jave Servlets, JavaBeans, ResourceBundles, and XML. Its technology also meets the standards of various Jakarta Commons packages, making it a universal framework that could be easily utilized in any setting. The framework supports application architectures based on the Model 2 approach. This provides a variety and offers web application developers

a choice aside from the more common Model-View-Controller (MVC) design paradigm.


Struts provide the Controller component. However, the Model and the View is based on integration and interaction with

other technologies. The interaction of standard data access technologies, like JDBC and EJBC, with Struts provides

the Model for the framework. Other third party packages like Hibernate, iBATIS or Object Relational Bridge also serve this purpose.

The View component is produced in much the same way as the Model. Common presentation systems like JavaServer Pages,

not excluding JSTL and JSF, Velocity Templates and XSLT are compatible with Struts.


Explain Jakarta Struts Framework?

The development of web based application of any size and scale is possible with Jakarta Struts framework. This open source

implementation of MVC (Model-View-Controller) allows for robust architecture. Thus it facilitates the design of scaleable,

reliable web applications with Java by making the design process much simpler.


Define Action Servlet.

Action Servlet is the class org.apache.struts.Action Servlet. This class is the controller in the Jakarta Struts Framework.

As the medium of delivery, the controller handles all requests to the server.


How To Make Available Message Resources Definitions to the Struts Framework?

Message Resources Definitions files are added to the struts-config.xml file through the <message-resources/> tag.

This is because the Message Resources Definitions files are simple .properties files that contain messages usable in the struts project.


What Is Action Class?

All database/business processing happens in the Action Class. All database related stuffs are encouraged to be performed

in the Action Class. The Action Class wraps around the business logic and it is a part of the Model. It serves to translate

the HttpServletRequest to the business logic. Using the Action requires us to Subclass and to overwrite the execute() method.

The parameterized class is bypassed by the ActionServlet (commad) to ActionForm through the execute() method.

ActionForward is the return type for the execute method. In turn, the Struts Framework forwards requests to the file

using the ActionForward according to the value of the returned ActionForward object.


Action Form

An ActionForm is a JavaBean functioning to extend org.apache.struts.action.ActionForm. When a client fills in a form and

entered it, the ActionForm object will be automatically populated on the server side. The ActionForm also functions to keep the session state ongoing for web application.

 

1. What is Struts?  


Struts is an open source software that helps developers to easily build web application. It is a web page development framework which comprises of Java Servlets, Java Server Pages, custom tags, and message resources into a single framework. It is also a cooperative platform for development teams as well as independent developers.


2. Explain the components of Struts?


Struts is based on the MVC design pattern and its components can be categorized into:

Model: Components like business logic / business processes and data are parts of this.

View: It contains JSP, HTML etc.

Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.



3. How will we make any Of the Message Resources Definitions file available to the Struts Framework Environment?


Message Resources Definitions file are simple property files which consists of messages that can be used in the struts applications. Message Resources Definitions files can also be added to the struts-config.xml file using <message-resources /> tag.

E.g. <message-resources parameter="Message Resources" />



4. What is Struts Validator Framework?


Struts Framework provides the functionality to validate the form data. This can be used to validate data on both the client side as well as server side. It emits the java scripts and can be used to validate data on the user’s browser and incase of server side validation, it is done by sub classing the From Bean with DynaValidatorForm class.

The Validator framework comes integrated with the Struts Framework and can be used without doing any extra change in settings.



5. Is struts thread safe?


Struts is thread safe as well as thread-dependant. Light-weight Action object handles the response to a request instead of individual servlets. The Action class is instantiated only once and lets the other requests to be threaded through the original object available. This technique helps to provide the best possible throughput and conserves resources. A properly-designed application will exploit this further by routing related operations through a single Action.



6. What are the core classes of the Struts Framework?


The core classes of Struts framework are:


ActionServlet is the back bone of the whole web application.


ActionForm is a Java bean that associates one or more ActionMappings.


The business logic is wrapped by the Action class which provides an interface to the Model of the application.


ActionMapping is used to provide mappings for Objects to Actions.


ActionForward represent the destination for the controller.



7. What are the different kinds of actions in Struts?


The different kinds of actions in Struts are as follows:

a. ForwardAction.

b. IncludeAction.

c. DispatchAction.

d. LookupDispatchAction.

e. SwitchAction.



8. What is Action Class?


The Action Class is a part of the Model. Its purpose is to translate the HttpServletRequest to the business logic and use the Action, we need to have a Subclass and overwrite the execute() method, In which all the database/ business processing are done. The ActionServlet (command) passes the parameterized class to Action Form using the execute() method and its return type is used by the Struts Framework to forward the request to the file according the value of the returned ActionForward object.



9. What are the various Struts tag libraries?


The various Struts tag libraries are:

a. Bean tag library – to access JavaBeans and their properties.

b. HTML tag library - to give standard HTML output, like forms, text boxes, etc.

c. Logic tag library – in order to generate conditional output, iteration capabilities and flow management.

d. Tiles or Template tag library - for those application using tiles.

e. Nested tag library – in order to use the nested beans in the application.



10. How the exceptions are handled in struts?


Exceptions in Struts are handled in two ways:

a. Programmatic exception handling: It is the explicit try/catch blocks in the code that can throw exception. It works well when any error occurs in the custom value

b. Declarative exception handling: In this we either define <global-exceptions> handling tags in the struts-config.xml or exception handling tags within <action></action> tag. It works well when error occurs in custom page and applies only to exceptions thrown by Actions.




11. What are the contents of web.xml and struts-config.xml? Explain the difference between them.



The web.xml file contains the information used by servlets and JSPs, having the description of the application, mapping information about servlets and URL, JSP configuration information, error page information without the exceptions.


The struts-config.xml file contains information about struts framework at the time of deploying the web application. It includes information about form bean, action mappings, controller information containing the buffer size, content type, etc.





12. What is SwitchAction & ForwardAction in struts?



A SwitchAction switches between modules and forwards the control to the URL specified in the new module. There are two parameters namely page, to which control is forwarded after switching and prefix that specifies the module to which the control is switched.

A ForwardAction is used to forward a request to the specified URL, represented as a destination to the controller to which it is sent after the action is completed.




13. What is Struts Flow?



Struts Flow is a port of Cocoon's Control Flow to Struts in order to allow complex workflow, like multi-form wizards, which is easily implemented using continuations-capable JavaScript. It provides the ability to describe the order of web pages that have to be sent to the client, at any given point of time in an application.




14. Why is ActionForm a base class rather than an interface?




Making ActionForm a class gives advantage of the single inheritance restriction of Java in order to make difficult for people to do things that they are not supposed to.


However, if ActionForm is implemented as interface encourages matching of property types to the underlying business tier, violating one of the important purpose of ActionForm and also encourages using of existing DAO objects which violates MVC design pattern. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值