Liferay5.2+struts2+jodo+maven例子

1.pom.xml

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>myPortal</groupId>
    <artifactId>myPortal</artifactId>
    <packaging>war</packaging>
    <name>myPortal</name>
    <version>1.0</version>
    <description>This is test Portal</description>
    <build>
        <finalName>myPortal</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <dependencies>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
        </dependency>


        <!--  common for portal  -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.opensymphony</groupId>
            <artifactId>xwork-core</artifactId>
            <version>2.1.6</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.6</version>
        </dependency>
        <!--
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>2.5.6</version>
        </dependency>
         -->
         
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
       
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.15</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-dojo-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency> 
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-portlet-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>liferay</groupId>
            <artifactId>util-taglib</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>cdc-respository</id>
            <name>cdc-respository</name>
            <url>http://127.0.0.1:8080/M2Repository</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>cdc-plugin-respository</id>
            <name>cdc-plugin-respository</name>
            <url>http://127.0.0.1:8080/M2Repository</url>
        </pluginRepository>
    </pluginRepositories>
</project>

 

2.applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
        "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
     <bean id="viewIndex" class="com.action.ViewIndexAction"></bean>
     <bean id="sayHello" class="com.action.JsonSayHelloAction"></bean>
</beans>
3.liferay-display.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 4.0.0//EN" "http://www.liferay.com/dtd/liferay-display_4_0_0.dtd">
<display>
    <category name="My Portal">
        <portlet id="myPortal">myPortal</portlet>
    </category>
</display>
4.liferay-portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 4.4.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_4_0.dtd">
<liferay-portlet-app>
 
  <portlet>
    <portlet-name>myPortal</portlet-name>
    <instanceable>true</instanceable>
  </portlet>
  <role-mapper>
    <role-name>administrator</role-name>
    <role-link>Administrator</role-link>
  </role-mapper>
  <role-mapper>
    <role-name>guest</role-name>
    <role-link>Guest</role-link>
  </role-mapper>
  <role-mapper>
    <role-name>power-user</role-name>
    <role-link>Power User</role-link>
  </role-mapper>
  <role-mapper>
    <role-name>user</role-name>
    <role-link>User</role-link>
  </role-mapper>
</liferay-portlet-app>
5.portlet.xml

<?xml version='1.0' encoding='UTF-8' ?>
<portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd' 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' version='1.0' id='struts-portlet'>
        <portlet id='myPortal'>
        <description xml:lang='EN'>myPortal_desc</description>
        <portlet-name>myPortal</portlet-name>
        <display-name xml:lang='EN'>myPortal_display</display-name>
        <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
        <init-param>
            <name>viewNamespace</name>
            <value>/view</value>
        </init-param>
        <init-param>
            <name>defaultViewAction</name>
            <value>viewIndex</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>
        <supported-locale>en</supported-locale>
        <resource-bundle></resource-bundle>
        <portlet-info>
            <title>myPortal</title>
            <short-title>myPortal</short-title>
            <keywords>struts,portlet</keywords>
        </portlet-info>
    </portlet>
</portlet-app>

6.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>myPortal</display-name>
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>myPortal.root</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
             /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

    <!-- listener -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--
        below area is for liferay portal contain work begin
    -->

    <servlet>
        <servlet-name>myPortal</servlet-name>
        <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
        <init-param>
            <param-name>portlet-class</param-name>
            <param-value>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>myPortal</servlet-name>
        <url-pattern>/myPortal/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>Cache Filter - Resource</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.cache.CacheFilter</param-value>
        </init-param>
        <init-param>
            <param-name>pattern</param-name>
            <param-value>2</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>Cache Filter - Resource CSS JSP</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.cache.CacheFilter</param-value>
        </init-param>
        <init-param>
            <param-name>url-regex-pattern</param-name>
            <param-value>.+/css/.jsp</param-value>
        </init-param>
        <init-param>
            <param-name>pattern</param-name>
            <param-value>2</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>Header Filter</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.header.HeaderFilter</param-value>
        </init-param>
        <init-param>
            <param-name>Cache-Control</param-name>
            <param-value>max-age=315360000, public</param-value>
        </init-param>
        <init-param>
            <param-name>Expires</param-name>
            <param-value>315360000</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>Header Filter - CSS JSP</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.header.HeaderFilter</param-value>
        </init-param>
        <init-param>
            <param-name>url-regex-pattern</param-name>
            <param-value>.+/css/.jsp</param-value>
        </init-param>
        <init-param>
            <param-name>Cache-Control</param-name>
            <param-value>max-age=315360000, public</param-value>
        </init-param>
        <init-param>
            <param-name>Expires</param-name>
            <param-value>315360000</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>GZip Filter</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.gzip.GZipFilter</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>Minifier Filter</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.minifier.MinifierFilter</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>Minifier Filter - CSS JSP</filter-name>
        <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
        <init-param>
            <param-name>filter-class</param-name>
            <param-value>com.liferay.portal.servlet.filters.minifier.MinifierFilter</param-value>
        </init-param>
        <init-param>
            <param-name>url-regex-pattern</param-name>
            <param-value>.+/css/.jsp</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Cache Filter - Resource</filter-name>
        <url-pattern>*.css</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Cache Filter - Resource</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Cache Filter - Resource</filter-name>
        <url-pattern>*.js</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Cache Filter - Resource CSS JSP</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.css</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.gif</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.ico</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.jpg</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.js</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter</filter-name>
        <url-pattern>*.png</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Header Filter - CSS JSP</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>GZip Filter</filter-name>
        <url-pattern>*.css</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>GZip Filter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>GZip Filter</filter-name>
        <url-pattern>*.js</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>GZip Filter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Minifier Filter</filter-name>
        <url-pattern>*.css</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Minifier Filter</filter-name>
        <url-pattern>*.js</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Minifier Filter - CSS JSP</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>1</servlet-name>
        <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
        <init-param>
            <param-name>portlet-class</param-name>
            <param-value>com.liferay.webform.portlet.WebFormPortlet</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>1</servlet-name>
        <url-pattern>/1/*</url-pattern>
    </servlet-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core_rt</taglib-uri>
            <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://liferay.com/tld/security</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-security.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://liferay.com/tld/theme</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-theme.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://liferay.com/tld/ui</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://liferay.com/tld/util</taglib-uri>
            <taglib-location>/WEB-INF/tld/liferay-util.tld</taglib-location>
        </taglib>
    </jsp-config>
    <!-- end -->

</web-app>

7.struts-my-view.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>
    <!--   namespace="/spc/view"  -->
    <package name="myPortal-view" extends="struts-portlet-default">
        <action name="viewIndex" class="viewIndex">
            <result name="success">/view/index.jsp</result>
        </action>
    </package>


    <package name="Struts2_AJAX_MyPortal" extends="json-default">
        <action name="sayHello" class="sayHello">
            <result type="json">
            </result>
        </action>
    </package>

</struts>
8.struts.properties

struts.objectFactory = spring
9.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.i18n.encoding" value="UTF-8"/>
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.action.extension" value="do"/>
<include file="struts-my-view.xml"/>

</struts>
10.JsonSayHelloAction

package com.action;

import com.opensymphony.xwork2.ActionSupport;

public class JsonSayHelloAction extends ActionSupport {
    private String sayHelloStr;
    public String getSayHelloStr() {
        return sayHelloStr;
    }
    public void setSayHelloStr(String sayHelloStr) {
        this.sayHelloStr = sayHelloStr;
    }
   
    @Override
    public String execute() throws Exception {
        sayHelloStr = "hello world Json";
        return SUCCESS;
    }
   
}

11ViewIndexAction

package com.action;

import com.opensymphony.xwork2.ActionSupport;

public class ViewIndexAction extends ActionSupport {

    @Override
    public String execute() throws Exception {
        System.out.println("====ViewIndexAction=====");
        return SUCCESS;
    }
   
}
12.index.jsp

<%@ page import="javax.portlet.*"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<portlet:defineObjects />
<%
String rootPath = request.getContextPath();
PortletPreferences prefs = renderRequest.getPreferences();
%>
 
<sx:head/>
<script type="text/javascript">
function callJson(){
dojo.io.bind({
    url: "<%=rootPath%>/sayHello.do",
    mimetype: "text/html",
    timeoutSeconds: 3000, 
    handle: function(type, data, evt){
      if(type == "load") { alert(data); } //data is that we wanted
      else if (type == "error") { alert(data.message); } //data is the error object
      else { ; } //other events maybe need handled
    }
  }); 
}
</script>
<div align="center">
       <a href="#" οnclick="callJson()">sayHello</a>
</div>

13.header.jsp

<%@ page import="javax.portlet.*"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<portlet:defineObjects />
<%
String rootPath = request.getContextPath();
PortletPreferences prefs = renderRequest.getPreferences();
%>

微信扫码订阅
UP更新不错过~
关注
  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pcjavanet

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值