"Java seconds technology seconds kill interviewer" common face question (i)

Source: Internet
Author: User

In 1.struts2, how does action get the data that the user has entered from the page, and how does it pass the data to the view layer?

A: (1) There are three ways the action gets data from the page:

        ①通过Action属性接收参数;(例:${pageContext.request.contextPath}/***.action? id=xxxx)        ②通过域模型获取参数;(例:ServletActionContext.getRequest().getParameter(arg0))        ③通过模型驱动获取参数(例:extends ModelDriven<T>)(2)Action将数据存入值栈(Value Stack)中,视图可以通过表达式语言(EL)从值栈中获取;

2. Describe how the action in Struts2 is written, and whether a singleton is used?

A: (1) The action of STRUTS2 has three kinds of wording:

       ①POJO类——无继承无实现;       ②实现Action接口,重写execute()方法;       ③继承ActionSupport(常用);   (2)Action没有像Servlet一样,使用单实例多线程的工作方式,很明显,每一个Action要接收不同用户的请求参数,这就意味着Action是有状态的,因此在设计上使用了,每一个请求对应一个Action的处理方式,所以是多例的。

3.struts2, action does not receive a user's request directly, why can it handle the user's request? And why do you know which action to handle for a request?

A: (1) when the STRUTS2 core filter receives the user's request, the user's request is simply preprocessed (such as parsing, encapsulating parameters), then the action instance is created by reflection and the method specified in action is called to process the user request.

    (2)通知具体调用哪个Action来处理请求的方式,有两种:      ①利用配置文件,Struts.xml中配置的<action>标签来确定;      ②利用约定,Struts2中可以使用约定(convention)插件。例如:约定xxx总是对应XxxAction,这是对约定优于配置理念的践行;

4. Describe the Struts2 exception handling mechanism?

A: Struts2 provides a declarative exception handling mechanism that can include the following code in the configuration file:

/web-inf/pages/error.jsp 5. Describe how the interceptor works? A: In Struts2, you can implement the Interceptor interface or inherit the Abstractinterceptor class to customize the Interceptor. The init () method in the ① interface is called immediately after the Interceptor is created, and it is called only once during the life cycle of the interceptor, and the relevant resources can be initialized as necessary in the method; ② each request is intercepted, The Intercept () method is called once; ③destory () Method will be called before the Interceptor is destroyed. 6. Talk about the difference between interceptors and filters? A: Interceptors and filters can be used to achieve crosscutting concerns, the main difference is that the ① interceptor is based on the Java reflection mechanism, and the filter is a function callback based ② filter dependent on the servlet container, The interceptor does not depend on the servlet container ③ interceptors can only work on action requests (the method in action), and filters can work on almost all requests (CSS JSP JS) 7. Talk about your project choosing Struts2 reasons? A: ①action is the Pojo class, does not rely on the servlet API, has good testability, ② powerful interceptor, simplifies the complexity of development, ③ support a variety of performance layer technology: JSP, Freemarker, ④ flexible authentication method; ⑤ Internationalization (i18n) Support ⑥ declarative exception management; ⑦ simplifies Ajax;⑧ via a JSON plugin with spring integration; 8. How do I access the HttpServletRequest, HttpSession, and ServletContext three domain objects in Struts2? A: There are two ways: ① is obtained by Servletactioncontext method, ② is injected through Servletrequestaware, Sessionaware, and Servletcontextaware interfaces. What is the role of the default package Struts-default in 9.struts2? A: It defines a number of interceptors and result types within the Struts2, and many of the core functions of STRUTS2 are implemented through these built-in interceptors, such as encapsulating parameters from requests to action, file uploads, and data validation, all through interceptors. In the STRUTS2 configuration file, the custom package inherits the Struts-default package, and you can use STRUTS2 to provide these features for us. 10. Describe the principle and life cycle of the value stack? A: Value-stack runs through the entire action lifecycle and is stored in the request scope, so it is the same as the request's life cycle. When Struts2 accepts a request, it creates aActioncontext, Value-stack, and action objects, and then the action is stored in Value-stack, so the instance variable of the action can be accessed through OGNL. Because the action is multi-instance, unlike a servlet using a singleton, each action has a corresponding value-stack,value-stack that holds the data type that is the instance of the action, and the instance variable in the action. The action object is saved by default at the top of the stack. is 11.SessionFactory thread-safe? is the session thread-safe? Can two threads share a session? A: (1) sessionfactory corresponds to Hibernate's concept of a datastore, which is thread-safe and can be accessed concurrently by multiple threads. Sessionfactory is generally only built when it is started. For applications, it is best to encapsulate the sessionfactory in a singleton pattern for easy access. (2) The session is a lightweight, non-thread-safe object (a session cannot be shared between threads), which represents a unit of work that interacts with the database. The session is created by Sessionfactory and is closed after the task is completed. The session is the primary interface that the persistence layer service provides externally. The session will delay getting the database connection (that is, it is only available when needed). To avoid creating too many sessions, you can use treadlocal to get the current session, no matter how many times you call the Getcurrentsession () method, the same session is returned. What is the difference between the 12.Session load and get methods? A: ① If no qualifying record is found, the GET method returns a null value, and the Load method throws an exception, the ②get method returns the entity class object directly, and the Load method returns the proxy for the entity class object; ③ before Hibernate3, The Get method only makes the data lookup in the first level cache (internal cache), and if no corresponding data is found, it crosses the level two cache and emits a SQL statement to complete the reading of the data, and the Load method can make full use of the existing data in the level two cache for lazy loading. Of course, starting from Hibernate3, the Get method is no longer a level two cache write-only, it can also access level two cache; simply, for the load () method, Hibernate believes that the data must exist in the database, can be assured that the use of agents to implement lazy loading, if there is no data , an exception is thrown, and the Get () method to fetch the data can be nonexistent. 13. Describe the session loading realThe process of body object? A: ①session before invoking the data query function, the first query in the cache, in a cache, the entity type and primary key query, if the first-level cache lookup hit and the data state is valid, then directly return; ② if the first-level cache is not hit, The next session will be queried in the current nonexists record (equivalent to a query blacklist, if duplicate invalid queries can be quickly judged, thereby improving performance), and if the same query condition exists in nonexists, the Null;③ is returned for the Load method, If the first-level cache query fails, query the level two cache, and if the level two cache hit is returned directly; ④ if none of the previous queries are hit, the SQL statement is issued and if the query does not find the corresponding record, the query is added to the nonexists of the session and returns null ⑤ based on the mapping configuration and SQL statements, get resultset, and create the corresponding entity object, ⑥ the object into session (first-level cache) management, ⑦ the OnLoad method to execute the interceptor (if there is a corresponding interceptor), ⑧ the data object into the level two cache; ⑨ returns the data object. What is the difference between the list method and the iterate method of the 14.Query interface? A: Each object returned by the ①list () method is complete (each property in the object is populated with a field in the table), the list method cannot take advantage of the cache, it is write-only to the first-level cache, and the ②iterate method can take full advantage of the first-level cache, which contains only primary key values (identifiers) in the returned object , Hibernate sends an SQL statement to the database again to get the property values of the object only when you are working on an object in iterator, and the ②list method does not cause n+1 query problems, and the iterate method causes n+1 query problems. 15.Hibernate How to realize paging query? A: With Hibernate, the developer only needs to provide a HQL statement, query the starting row (Setfirstresult () method), and the maximum number of query rows (the Setmaxresult () method), and invoke the list () method of the query interface. Hibernate automatically makes the SQL statement for the page query.

Java seconds technology seconds to kill interviewer (s) Common face question (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.