当前位置: 代码迷 >> Web前端 >> liferay6.1的SSI调整3(SDK开发)
  详细解决方案

liferay6.1的SSI调整3(SDK开发)

热度:239   发布时间:2012-11-22 00:16:41.0
liferay6.1的SSI整合3(SDK开发)
主要的一些配置文件:
User_sqlMap.xml(放在src/com/ibitis目录下面,目录自己建)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
	"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
	<typeAlias alias="user" type="com.vo.User"/>
	
	<insert id="saveUser" parameterClass="user">
<!-- 		<selectKey keyProperty="id" resultClass="int">
			<![CDATA[
				select (max(id)+1) as value
			]]>
		</selectKey> -->
		<![CDATA[
			insert into student(name,age)
			values(#name#,#age#)
		]]>
	</insert>
	
	<delete id="deleteUser" parameterClass="int">
		<![CDATA[
			delete from student where id=#id#
		]]>
	</delete>
	
	<select id="getAllUsers" resultClass="user">
		<![CDATA[
			select * from student
		]]>
	</select>
	
	<update id="updateUser" parameterClass="user">
		<![CDATA[
			update z_user set
			name=#name#,
			age=#age#,
			where id=#id#
		]]>
	</update>
	
	<select id="findUserById" parameterClass="int" resultClass="user">
		<![CDATA[
			select * from student where id=#id#
		]]>
	</select>
	
</sqlMap>



struts.properties(src目录下)
struts.devMode=true
struts.enable.DynamicMethodInvocation=false
struts.objectTypeDeterminer=notiger
struts.objectFactory=spring
struts.locale=zh_CN
struts.i18n.encoding=UTF-8


struts.xml (src目录下)
<?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>
	<package name="iis" namespace="/ssi" extends="struts-portlet-default">
		<action name="findUser" class="userAction" method="findAllUsers">
			<result name="finduser">/jsp/finduser.jsp</result>
		</action>
		<action name="index" class="userAction" method="ssi">
			<result name="view">/jsp/view.jsp</result>
		</action>
		<action name="add" class="userAction" method="addUser">
			<result name="addUserSuccess">/jsp/addUserSuccess.jsp</result>
		</action>
	</package>

</struts>


actionContext.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType" 
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<!-- Struts2 action类注入 -->
	<bean id="userAction" class="com.action.UserAction" scope="prototype">
		<property name="userService" ref="userService" />
	</bean>
</beans>


applicationContext.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <import resource="actionContext.xml"/>  
    <import resource="daoContext.xml"/>  
    <import resource="dataAccessContext.xml"/>  
    <import resource="serviceContext.xml"/>  
</beans>


daoContext.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType" 
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<!-- IBATIS的DAO的配置注入 -->	
	<bean id="userDao" class="com.daoImpl.UserDao">
		<property name="sqlMapClient" ref="sqlMapClient"/>
	</bean>	
	
</beans>



dataAccessContext.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<!-- 读取 jdbc.properties -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>WEB-INF/jdbc.properties</value>
			</list>
		</property>
	</bean>

	<!-- 配置数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="poolPreparedStatements" value="true" />
	</bean>

    <!-- 配置sqlMapClient -->
	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource">
			<ref local="dataSource"/>
		</property>
		<property name="configLocation">
			<value>WEB-INF/sqlMapConfig.xml</value>
		</property>
	</bean>
</beans>



serviceContext.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType" 
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

	<!-- 系统业务逻辑层的注入 -->
	<bean id="userService"
		class="com.serviceImpl.UserServiceImpl">
		<property name="userDao" ref="userDao"></property>
	</bean>
</beans>


sqlMapConfig.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
     <sqlMap resource="com/ibitis/User_sqlMap.xml"/>   
</sqlMapConfig>


jdbc.properties(docroot/WEB-INF/目录下)
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/lportal
jdbc.username=root
jdbc.password=123

这个按你自己的实际情况填写

liferay-display.xml(docroot/WEB-INF/目录下)
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.1.0//EN" "http://www.liferay.com/dtd/liferay-display_6_1_0.dtd">

<display>
	<category name="category.sample">
		<portlet id="ssi" />
	</category>
</display>


liferay-portlet.xml(docroot/WEB-INF/目录下)
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.1.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_1_0.dtd">

<liferay-portlet-app>
		<portlet>
		<portlet-name>ssi</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>


portlet.xml(docroot/WEB-INF/目录下)
<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
		 <portlet>
		<portlet-name>ssi</portlet-name>
		<display-name>SSI</display-name>
	<portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
	    <init-param>  
	         <name>viewNamespace</name>  
	         <value>/ssi</value>  
        </init-param>  
        
	        <init-param>  
                <name>defaultViewAction</name>  
	            <value>index</value>
	        </init-param>  

		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
		</supports>
		<portlet-info>
			<title>SSI</title>
			<short-title>ssi</short-title>
			<keywords></keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet> 
</portlet-app>



web.xml(docroot/WEB-INF/目录下)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>portlet-test-portlet</display-name>
	<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>
	<jsp-config>
		<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/aui</taglib-uri>
			<taglib-location>/WEB-INF/tld/aui.tld</taglib-location>
		</taglib>
	</jsp-config>
	


        <context-param>
               <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
		   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>  
       <filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>  
      	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
</web-app>



还有两个JSP页面:(docroot/WEB-INF/jsp目录下)
view.jsp
<%@ page language="java" contentType="text/html; utf-8" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
 function check(){
	 var age =document.getElementById("age").value;
	 var name =document.getElementById("name").value;
	 if(isNaN(age)||age==""){
		 alert("请填写正确年龄");
		 return false;
	 }
	 if(name==""){
		 alert("请填写正确姓名");
		 return false;
	 }
    form1.submit;
 }

</script>

<body>
<s:form action="add" method="post" namespace="/ssi" name="form1"  >
	<s:textfield name="user.name" id="name" label="name" />
	<s:textfield name="user.age" id="age" label="age" />
	<s:submit type="button" onclick="return check()"></s:submit>
</s:form>

<s:form action="findUser" method="post" namespace="/ssi">
	<s:submit value="查看用户" ></s:submit>
</s:form>
</body>
</html>


<%-- 
<s:form action="add"  namespace="/ssi"> 
<s:textfield name="name" label="name"/> 
<s:textfield name="age" label="age"/> 
<s:submit /> 
</s:form>	
<s:form action="show" namespace="/ssi">
<s:submit>查找</s:submit>
</s:form> --%>


addUserSuccess.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>addUserSuccess
</body>
</html>


1 楼 animo_itey 2 小时前  
楼主 extends="struts-portlet-default"这里一定要这样写吗?
通常都是下面这种写法!
struts-default
2 楼 sweat89 1 小时前  
animo_itey 写道
楼主 extends="struts-portlet-default"这里一定要这样写吗?
通常都是下面这种写法!
struts-default

这里的struts2集成了liferay,所以要  extends="struts-portlet-default"