创建Action类
package com.liferay.portlet.strutsdemo;
- import javax.portlet.ActionRequest;
- import javax.portlet.ActionResponse;
- import javax.portlet.PortletConfig;
- import javax.portlet.RenderRequest;
- import javax.portlet.RenderResponse;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import com.liferay.portal.struts.PortletAction;
- public class StrutsAction extends PortletAction {
- public void processAction(ActionMapping mapping, ActionForm form,
- PortletConfig config, ActionRequest req, ActionResponse res)
- throws Exception {
- String name = req.getParameter("name");
- if (null == name || "".equals(name)) {
- setForward(req, "sturts_portlet.err");
- } else {
- setForward(req, "sturts_portlet.success");
- }
- }
- public ActionForward render(ActionMapping mapping, ActionForm form,
- PortletConfig config, RenderRequest req, RenderResponse res)
- throws Exception {
- if (getForward(req) != null && !getForward(req).equals("")) {
- return mapping.findForward(getForward(req));
- } else {
- return mapping.findForward("sturts_portlet.view");
- }
- }
- }
成功和错误页面不在写,可以根据自己的需要编写了
部署Portlet
打开Ant界面,Eclipse--》show views--》ant 添加build文件,找到Ext工程下面的build.xml文件,点击其中的
Direct-deploy。
完成之后,启动liferay-tomcat
在浏览中输入http://localhost:8080,登录,添加portlet