---
title: " ActionRequest，RenderRequest，HttpServletRequest及其意"
author: "java_frog"
date: "2009-05-22T16:38:32Z"
tags: []
slug: "actionrequest-renderrequest-httpservletrequest"
draft: false
lastmod: "2009-05-22T16:38:32Z"
id: 393560
url: "https://java-frog.iteye.com/blog/393560"
---

由于每个页面中，每个Portlet 的运行都相对比较独立，因此，为了实现Porlet 的异步功能，有必要在Request 内区分每个Portlet 的信息。因此，针对Portlet 区分出了两类Request，ActionRequest 和RenderRequest。

ActionRequest 
来源：javax.portlet.ActionRequest
 ActionRequest 是Portlet 的标准接口，主要标识在页面中单个Portlet 的请求。其作为从Web 客户端到服务端的信息载体。其中的内容为单个Portlet 中的内容。
Liferay实现为：com.liferay.portlet.ActionRequestImpl



RenderRequest 
来源：javax.portlet.RenderRequest
RenderRequest 也是Portlet 的标准接口。可用于Portlet 之间的数据共享。只有RenderRequest 能够在服务端容器当中转发请求。
Liferay实现为：com.liferay.portlet.RenderRequestImpl



HttpServletRequest 
来源：javax.servlet.http.HttpServletRequest
这个就不用说了，该类的实例是整个页面请求的信息载体。所有Portlet 的信息都打包在这里，可以视作是包涵了众多Portlet 的一个航母。猜想应该是所有Portlet 的ActionRequest 打包后放入HttpServletRequest 内。当单个Portlet 交互时仅仅只从中对应的 ActionRequest 取出数据来用。

根据JSR 168 的定义Portlet 的实现如下：


```java
public class MyPortlet extends GenericPortlet
{
         public void doView( RenderRequest request, RenderResponse response )
         throws PortletException, IOException
　　 {
                //自己的处理代码
　　 }

　　 public void doEdit( RenderRequest request, RenderResponse response )
　　 throws PortletException, IOException
　　 {
                //自己的处理代码
　　 }

　　public void render( RenderRequest request, RenderResponse response )
　　 throws PortletException, IOException
        {
                //自己的处理代码
　　 }

　　 public void processAction( ActionRequest request, ActionResponse response )
　　 throws PortletException, IOException
　　 {
                //ActionRequest类型的request可以使用getParameter
           if( request.getParameter(FORM_SUBMIT) != null ) {
	// Set form text in the session bean
	AaPortletSessionBean sessionBean = getSessionBean(request);
			if( sessionBean != null )
	sessionBean.setFormText(request.getParameter(FORM_TEXT));
		}
　　 }
}
```

        Portlet 中有两种请求方式：actionRequest 和renderRequest 。当portlet容器接收到一个actionRequest  请求的时候，如果请求后的Portlet 模式为view，那么Portlet 容器先调用Portlet 的processAction 方法，然后调用 portlet 的Render 方法去执行portlet 的doView() 方法；如果请求后的Portlet模 式为edit ，则最后去调用doEdit ()方法。当Portlet 容器接收到一个renderRequest 请求的时候，它将不会调用processAction 方法，Portlet 容器直接 调用Render 方法以执行对应的view 模式对应的doView() 方法或是edit 模式对应的doEdit() 方法。