除了tag基本上研究了一下,一开始不要看tag,从它那个controller入手,然后看它处理xml配置(这个一开始也可以跳过),然后就是看它的影射处理,原码没必要完全搞清楚,主要是学习整个系统的架构(struts的一些代码真的是写得很漂亮)
解决方案 »
- Hibernate 添加oracle本机时间出错。
- 16进制字符串如何比较大小
- mysql的UTF8编码问题。。
- 请问断掉网线的tomcat如何启动
- 求jfreechart出的图片直接转为byte[]数组怎么玩
- cmr调用错误:A CMR collection may only be used within the transction in which it was created
- 【求助】deploytool不能连上localhost??
- java做cs模式的应用程序好吗?
- 我个人藏书,给大家看看,希望大家也给我介绍一些好书.
- 关于@transactional使用在接口上的问题
- 各位EJB的同僚看过来
- 求教:xml文件中的数据导入到数据库中,用java来实现
细节上主要把握struts-config.xml,ActionServlet,ActionForm,Action.
至于标签库要慢慢看,不能性急。
基本上是jsp->formBean->actionBean->jsp的逻辑。
formBean可以取出jsp表单数据。actionBean作数据处理和视图控制
其中又有两个工作是ActionServlet的核心工作。
1、ActionServlet初始化工作,其中initServlet是重要的函数之一,另外就是init开发的其它几个函数。
2、在ActionServlet中主要是调用了RequestProcessor的process函数进行一些请求处理:
public void process(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException { // Wrap multipart requests with a special wrapper
request = processMultipart(request); // Identify the path component we will use to select a mapping
String path = processPath(request, response);
if (path == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Processing a '" + request.getMethod() +
"' for path '" + path + "'");
} // Select a Locale for the current user if requested
processLocale(request, response); // Set the content type and no-caching headers if requested
processContent(request, response);
processNoCache(request, response); // General purpose preprocessing hook
if (!processPreprocess(request, response)) {
return;
} // Identify the mapping for this request
ActionMapping mapping = processMapping(request, response, path);
if (mapping == null) {
return;
} // Check for any role required to perform this action
if (!processRoles(request, response, mapping)) {
return;
} // Process any ActionForm bean related to this request
ActionForm form = processActionForm(request, response, mapping);
processPopulate(request, response, form, mapping);
if (!processValidate(request, response, form, mapping)) {
return;
} // Process a forward or include specified by this mapping
if (!processForward(request, response, mapping)) {
return;
}
if (!processInclude(request, response, mapping)) {
return;
} // Create or acquire the Action instance to process this request
Action action = processActionCreate(request, response, mapping);
if (action == null) {
return;
} // Call the Action instance itself
ActionForward forward =
processActionPerform(request, response,
action, form, mapping); // Process the returned ActionForward instance
processForwardConfig(request, response, forward); }从上面的代码基本上可看出了处理请求的过程,从数据验证到action现到转发。
这里是你研究Struts源程序要注意的核心部分。******************************
ActionServlet提供了公共方法,可以被Action类实例使用。本节我们简要讨论一些方法:关于ActionServlet方法的更详细信息,请参数在http://jakarta.apache.org/struts中的Struts文档。
ActionServlet有允许我们增加或删除ActionForm beans、ActionForwards和ActionMappings的方法。这些方法的基本形式如下所示:
public void addFormBean(ActionFormBean formBean)
public void removeBean(ActionFormBean formBean)
public void addForward(ActionForward forward)
public void removeForward(ActionForward formward)
public void addMapping(ActionMapping mapping)
public void removeMapping(ActionMapping mapping)
每个定义显示了方法的范围(都是public)、方法返回的对象(都为void)以及方法的参数,下列方法根据名字找到这些对象:
public ActionFormBean findFormBean(String name)
public ActionForward findForward(String name)
public ActionMapping findMapping(String name)
接下来的两个方法用于处理数据源:
public void addDataSource(String key,DataSource ds)
public Datasource findDataSource(String key) – trturns a DataSource instance
findDataSource()方法用名字查找数据源。数据源可能是在Struts配置文件中静态定义的,也可能是用addDataSource()方法动态增加的。
最后,我们可以用下列的destroy()方法很优雅地关闭ActionServlet,并用reload()方法从Struts配置文件中重新装入信息到ActionServlet。*********************************************
ActionSetvlet是控制器主要组成部分,它由Struts类org.apache.struts.action. ActionServlet实现。这个类继承了标准javax.servlet.http.HttpServlet类。在处理请时控制器完成下列任务:
1.为到来的请求找到请求URI
2.把URI映射到适当的ActionMapping
3.创建或找到封装为当前映射定义的所有信息的ActionMapping实例
4.如果在映射中声明了的话,创建或找到ActionForm bean实例,用request参数去试着产生一个bean的属性。
5.对在ActionMapping中声明的Action类实例调用适当的perform()方法,给它传递ActionForm bean(如果在映射中声明)、ActionMapping对象、request对象和response对象。
6.接受从perform()方法返回的ActionForward,转发response到由ActionForward指定的源。
MSN :[email protected]
qq : 57473763
STRUTS学起来就很快的;如果要精通,就要不断的做。
了解这个之后,那就是看Taglib了,还有……
我的MSN是[email protected]
不过我不喜欢目空一切,代码又写不出或写出也是一堆SHIT的人,也不喜欢只会说人怎样,不知自己怎样的人。