1. Struts is integrated into container in web.xml as an filter. It is different from Spring, which is an Listener.
<?xml version="1.0" encoding="UTF-8"> ... <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-patter> </filter-mapping> ... </xml>
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
<action name="Register" class="manning.Register"> <result>/RegistrationSuccess.jsp</result> <result name="input">/Registration.jsp</result> </action>
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:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>manning</param-value> </init-param> </filter>
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
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="Menu"> <result>/menu/Menu.jsp</result> </action> </package> <include file="manning/chapterTwo/chapterTwo.xml"/> <include file="manning/chapterThree/chapterThree.xml"/> . . . <include file="manning/chapterEight/chapterEight.xml"/> </struts>
6. Action 通过 extend ActionSupport来继承default execute()实现. ActionSupport相当于java里的wrapper类. 同时ActionSupport还提供很多有用的方法, 比如配合ValidationInterceptor的addFieldError()方法.
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:
<h4>Complete and submit the form to create your own portfolio.</h4> <s:form action="ImageUpload" method="post" enctype="multipart/form-data"> <s:file name="pic" label="Picture"/> <s:submit/> </s:form>
? Where is the type of file
? what is the path of the "pic" file.
12. OGNL = expression (in JSP) + data type converter(struts)
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 <s:textfield name="XXX", label="..."/> 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
相关推荐
3. **Struts框架**:Struts是Java Web开发中常用的MVC框架,笔记中会讲解其架构、配置文件、Action类的编写、Struts拦截器以及如何整合其他技术如Hibernate和Spring。 4. **JSP培训笔记**:JSP(Java Server Pages...
7. **部分面试题答案.doc**:这份文档可能是针对软件工程师面试常见问题的答案,包括算法、设计模式、系统架构等方面,有助于准备面试和提升技能。 8. **JSP笔记.doc**:JavaServer Pages(JSP)是用于创建动态Web...
笔记可能介绍了Struts的工作原理、Action类、配置文件、Interceptor(拦截器)以及Struts2的使用。 9. **JDBC.doc**: JDBC(Java Database Connectivity)是Java连接数据库的标准API。笔记可能涵盖了连接数据库、...
8. **Java笔试**:这些文档可能包含Java语言的常见面试题和笔试题,包括语法、类库、面向对象特性、异常处理、内存管理等方面的问题。 以上内容覆盖了Java开发的核心领域,对于初学者和有经验的开发者来说,都是...
理解数据库设计原则,如范式理论,以及性能优化技巧,如索引的使用、查询优化、存储引擎的选择等,也是面试中常见的问题。 这个压缩包的学习资料可能包括PDF文档、笔记、代码示例等形式,帮助你系统复习和巩固这些...
在面试中,Spring MVC的工作机制是一个常见的问题。Spring MVC的流程大致如下: 1. 所有的HTTP请求首先由DispatcherServlet捕获。 2. DispatcherServlet根据HandlerMapping找到对应的Controller来处理请求。 3. ...
"部分面试题答案.doc"则可能包含了一些常见的Java和C++面试问题,比如多线程、内存管理、设计模式等。 综上所述,软件工程师在Java和C++领域的学习和实践中,不仅需要掌握编程语言本身,还需要了解相关的框架和工具...