2009年12月3號
Struts2.1.8.1 + Pluto1.1.7 + portletV1.0(JSR 168) CRUD Demo(20091203止)
本來想用portlet2.0(JSR 268)整合Struts2的,但是Struts2的最新版的Portlet插件JAR包也僅僅支持JSR 168規範,所以只能退回去用戶JSR168了。。。
由於Pluto1.X系列和Pluto2.X系列配置PortletV1.0和V2.0的配置文件不同,這裡不闡述1系列的配置步驟,只提供已經由手工配置好的apache-tomcat-6.0.20版本+Pluto1.1.7版本+PortletV1.0版本的TOMCAT應用服務器(注意附件要將三部份全部下載完才可以應用)
如圖所示:展示Struts2與Portlet1.0 整合的數據CRUD操作(增刪改查)
DEMO源代碼結構圖:
部份源代碼展示:
package cn.myhongkongzhen.demo.portlet.action;
import java.util.List;
import cn.myhongkongzhen.demo.portlet.bean.UserBean;
import cn.myhongkongzhen.demo.portlet.service.IUserService;
import cn.myhongkongzhen.demo.portlet.service.impl.UserServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
/*******************************************************************************
* User Actions
*
* @author Jane
*
*/
public class UserAction extends ActionSupport {
private IUserService service;
private String userName;
private String password;
private String userId;
private List<UserBean> listUser;
private static final long serialVersionUID = -1750501914156696345L;
public String add() {
UserBean user = new UserBean();
user.setPassword(password);
user.setUserName(userName);
service = new UserServiceImpl();
service.addUser(user);
return "success";
}
public String delete() {
service = new UserServiceImpl();
service.delete(Integer.parseInt(userId));
return "success";
}
public String editReady() {
return "editReady";
}
public String edit() {
service = new UserServiceImpl();
UserBean user = new UserBean();
user.setId(Integer.parseInt(userId));
user.setUserName(userName);
user.setPassword(password);
service.edit(user);
return "success";
}
public String listUser() {
service = new UserServiceImpl();
listUser = service.listAllUser();
return "list";
}
public String viewIndex() {
return "viewIndex";
}
public String addReady() {
return "addReady";
}
public String editIndex() {
return "editIndex";
}
public String helpIndex() {
return "helpIndex";
}
public IUserService getService() {
return service;
}
public void setService(IUserService service) {
this.service = service;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<UserBean> getListUser() {
return listUser;
}
public void setListUser(List<UserBean> listUser) {
this.listUser = listUser;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
<?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.i18n.encoding" value="UTF-8" />
<package name="user" extends="struts-portlet-default"
namespace="/user" abstract="true">
<default-class-ref
class="cn.myhongkongzhen.demo.portlet.action.UserAction">
</default-class-ref>
</package>
<package name="view" extends="user" namespace="/user/view">
<action name="user_*" method="{1}">
<result name="viewIndex">/jsp/view/index.jsp</result>
<result name="list">/jsp/view/list.jsp</result>
</action>
</package>
<package name="edit" extends="user" namespace="/user/edit">
<action name="user_*" method="{1}">
<result name="editIndex">/jsp/edit/index.jsp</result>
<result name="addReady">/jsp/edit/add.jsp</result>
<result name="editReady" type="redirect">
/jsp/edit/edit.jsp?userId=${userId}&userName=${userName}&password=${password}
</result>
<result name="success" type="redirect">
/user/view/user_listUser.action
</result>
</action>
</package>
<package name="help" extends="user" namespace="/user/help">
<action name="user_*" method="{1}">
<result name="helpIndex">/jsp/help/index.jsp</result>
</action>
</package>
</struts>
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet id="Struts2PortletDemo">
<description>Struts 2 Portlet Demo</description>
<portlet-name>Struts2PortletDemo</portlet-name>
<portlet-class>
org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher
</portlet-class>
<init-param>
<name>portletNamespace</name>
<value>/user</value>
</init-param>
<init-param>
<name>viewNamespace</name>
<value>/view</value>
</init-param>
<init-param>
<name>defaultViewAction</name>
<value>user_viewIndex</value>
</init-param>
<init-param>
<name>editNamespace</name>
<value>/edit</value>
</init-param>
<init-param>
<name>defaultEditAction</name>
<value>user_editIndex</value>
</init-param>
<init-param>
<name>helpNamespace</name>
<value>/help</value>
</init-param>
<init-param>
<name>defaultHelpAction</name>
<value>user_helpIndex</value>
</init-param>
<expiration-cache>1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>Struts 2 Portlet Demo</title>
</portlet-info>
</portlet>
</portlet-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- <servlet id="Struts2PortletDispatcherServlet">
<servlet-name>Struts2PortletDispatcherServlet</servlet-name>
<servlet-class>
org.apache.struts2.portlet.dispatcher.DispatcherServlet
</servlet-class>
</servlet>
-->
<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-pattern>
</filter-mapping>
<servlet>
<servlet-name>Struts2PortletV1Demo</servlet-name>
<servlet-class>
org.apache.pluto.core.PortletServlet
</servlet-class>
<init-param>
<param-name>portlet-name</param-name>
<param-value>Struts2PortletDemo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Struts2PortletV1Demo</servlet-name>
<url-pattern>/PlutoInvoker/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<h2>
User List Page
</h2>
<table>
<tr>
<th>
Id
</th>
<th>
UserName
</th>
<th>
Operate
</th>
</tr>
<s:iterator value="%{listUser}" var="user">
<tr>
<td>
<s:property value="%{id}" />
</td>
<td>
<s:property value="%{userName}" />
</td>
<td>
<s:url action="user_editReady" portletUrlType="action"
namespace="/user/edit" id="editUrl">
<s:param name="userId" value="%{id}" />
<s:param name="userName" value="%{userName}" />
<s:param name="password" value="%{password}" />
</s:url>
<a href='<s:property value="%{editUrl}" />'>Edit</a>
</td>
<td>
<s:url action="user_delete" portletUrlType="action"
namespace="/user/edit" id="deleteUrl">
<s:param name="userId" value="%{id}" />
</s:url>
<a href='<s:property value="%{deleteUrl}" />'>Delete</a>
</td>
</tr>
</s:iterator>
</table>
<p>
<ul>
<li>
<a href='<s:url action="user_addReady" portletMode="edit"/>'>Go
to Add User Page</a>
</li>
<p>
<li>
<a href='<s:url action="user_viewIndex" portletMode="view" />'>Go
to View Index Page</a>
</li>
<li>
<a href='<s:url action="user_editIndex" portletMode="edit" />'>Go
to Edit Mode</a>
</li>
<li>
<a href='<s:url action="user_helpIndex" portletMode="help" />'>Go
to Help Mode</a>
</li>
</ul>
<%@ page language="java" isErrorPage="true" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<h2>
Add User
</h2>
<s:form action="user_add">
<table>
<s:textfield name="userName" label="userName" />
<s:password name="password" label="password" />
<s:submit value="Add User" />
</table>
</s:form>
<%@ page language="java" isErrorPage="true" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<h2>
Edit User
</h2>
<s:form action="user_edit">
<table>
<s:hidden name="userId" value="%{userId}" />
<s:textfield name="userName" label="userName" value="%{userName}" />
<s:password name="password" label="password" value="%{password}" />
<s:submit value="Edit User" />
</table>
</s:form>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<h1>
Struts 2 Portlet Demo :
<br>
Mode Edit
</h1>
<ul>
<li>
<a href='<s:url action="user_addReady" />'>Go to Add User Page</a>
</li>
<p>
<li>
<a href='<s:url action="user_helpIndex" portletMode="help" />'>Go
to Help Mode</a>
</li>
<li>
<a href='<s:url action="user_viewIndex" portletMode="view" />'>Go
to View Mode</a>
</li>
</ul>
<<s:url></s:url>
其餘代碼在附件中的源代碼中
注意:DEMO中的相關jar包是通過tomcat中lib中引入的,將附件中的DEMO源碼下載下來后腰手工修改引入jar的位置,最好將附件中的tomcat-pluto-1三個部份zip下下來,重新制定tomcat的位置,然後修改工程中引入jar包的位置
歡迎討論
參考:
Struts2 Portlet Plugin(http://struts.apache.org/2.x/docs/portlet-plugin.html)
Pluto1.1 Getting Start(http://portals.apache.org/pluto/v11/getting-started.html)
Portlet API 1.0
Struts2 API
Struts---Portlet---Plugin API
- 大小: 373 KB
- 描述: Struts2Pluto1PortletV1.0Demo源代碼結構圖
- 大小: 62.3 KB
分享到:
相关推荐
【标题】"jsr168 portlet(struts2+spring2.5+hibernate3.3)" 是一个基于Java技术栈的Web应用程序开发示例,它利用JSR168规范来创建portlet,同时结合了Struts2、Spring2.5和Hibernate3.3这三大框架,为构建可重用、...
Struts2_Portlet Pluto_Demo 是一个基于Struts2框架和Pluto Portlet Container的示例项目,旨在展示如何在Java Portlet环境下利用Struts2进行开发。这个项目可以帮助开发者理解如何将流行的MVC框架Struts2与portlet...
D:\pluto2>mvn pluto:install -DinstallDir="${TOMCAT_HOME}" ``` 注意:如果 `${TOMCAT_HOME}` 路径中含有空格,则需要将路径用引号括起来。 ###### 2.5.4 添加 commons-logging-api-1.1.jar 文件 从网上下载 `...
unbutu gnuradio 实现pluto的FM收听功能
- **Portlet类型**:常见的Portlet类型包括JSR 286(Portlet 2.0)和JSR 168(Portlet 1.0),它们定义了Portlet的API,使得开发人员能够创建跨平台的应用。 2. **Pluto Portlet Container**: - **Pluto介绍**:...
Pluto是一个符合JSR-168标准的portlet容器,它允许开发者创建和管理portlet,这些portlet可以在一个统一的用户界面上显示。而Tomcat是Apache软件基金会的一个开源项目,它是Java Servlet和JavaServer Pages(JSP)的...
`struts2-portlet-2.0.1.war` 展示了Struts2与portlet容器的集成,如Liferay或Pluto。这在企业级应用中尤其重要,因为portlet可以部署在门户服务器上,与其他应用进行交互。这个实例有助于理解portlet开发和Struts2...
PLUTO SDR ,使用GNU Radio搭建简单FM接收
总结来说,Apache Pluto Portal的学习需要掌握portlet的基本概念,理解portlet与servlet的差异,以及JSR168和JSR286带来的新特性。此外,深入了解portal、portlet和portlet容器的关系对于开发和部署portlet应用程序...
**Struts2-Portlet**是Struts2框架的一个扩展,专门用于开发符合JSR 168标准的Portlet。该框架充分利用了Struts2的强大功能,使得开发者可以更加专注于业务逻辑的实现而无需过多关注底层细节,从而显著提高了开发...
在myeclipse6中,选择“File” > “New” > “Other” > “Web” > “Portlet Project”,输入项目名(例如:HelloWorldPortalDemo),选择Pluto作为portlet容器,遵循JSR 168或JSR 286标准,然后点击“Finish”。...