Struts2 In Action读书笔记以及面试常见问题

1. Struts is integrated into container in web.xml as an filter. It is different from Spring, which is an Listener.


...

	struts2
	org.apache.struts2.dispatcher.FilterDispatcher



	struts2
	/*

...

 2. Struts uses JavaBean to carry the data from JSP to Action and vice versa. The JavaBean is defined as properties and its set and get methods.

After transferred with the request, the data from JSP is stored in ValueStack and in the action (Struts initializes one action object for each request. In contrast, the container initializes only one servlet to serve all the requests).

 

3. When we do not define actions in struts.xml, we want instead, use annotation in java to do so. By doning this, there is no below definition in struts.xml


/RegistrationSuccess.jsp
/Registration.jsp

 as we lost the action -> class mapping, we need to specify the default location to find the action classes, so we tell struts where to find the annotation:


struts2
org.apache.struts2.dispatcher.FilterDispatcher


actionPackages
manning

 The framework looks for classes either implement Action interface or named XXXAction for actions.

 

5. struts-default package provides lots of useful intercepter and etc. Normally, our action package should be inheriting it in struts.xml





extends="struts-default">

/menu/Menu.jsp




. . .

 

6. Action 通过 extend ActionSupport来继承default execute()实现. ActionSupport相当于java里的wrapper类. 同时ActionSupport还提供很多有用的方法, 比如配合ValidationInterceptor的addFieldError()方法.


Struts2 In Action读书笔记以及面试常见问题_第1张图片
 

7. ValidationIntercepter如果发现有error, 将redirect the workflow到action的"input" result. 

Filter VS Action

- Filter只能执行定义在filterclass的logic. 而Intercepter能够执行action class里面的方法. e.g. the public void validate() 方法.

 

8. Struts implements i18N with ActionSupport's TextProvider.

 

9. Model driver could be used to transfer obejct between Page and Actions.

 

10. ParameterIntercepter passes params from Page to action & ValueStack. (what is relationship between parameterintercepter and OGNL?)

 

11. FileUploadIntercepter gets run before ParamIntercepter. It converts File into Parameters:

 

Complete and submit the form to create your own portfolio.

 ? Where is the type of file

 

? what is the path of the "pic" file.

 

12. OGNL = expression (in JSP) + data type converter(struts)


Struts2 In Action读书笔记以及面试常见问题_第2张图片
 13. steps to define customized OGNL converter

1) write a class to extend StrutsTypeConverter's two abstract methods:

public abstract Object convertFromString(Map context, String[] values,
Class toClass);
public abstract String convertToString(Map context, Object o); 

 2) connect the field name in to class in .property file: XXX=ConverterClassName

 

to be continued...

 

struts 2 interview questions: http://www.journaldev.com/2354/struts2-interview-questions-and-answers#custom-interceptor

 

你可能感兴趣的:(编程技术)