<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    唯美古典
    Java入門,Struts,Hibernate,Spring,Groovy,Grails
    posts - 7,comments - 10,trackbacks - 0

    1、MyEclipse下建立一個web應用

    2、導包

    從解壓后的 spring 文件夾中尋找 jstl.jarstandard.jarspring.jarspring-webmvc.jarspring-webmvc-portlet.jarcommons-logging.jar拷貝到 WEB-INF/lib 目錄下。

    3、編輯web.xml

    web.xml文件中添加以下代碼:

    <!-- 設定Spring的根上下文 -->

        <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>

        <!-- 設定ViewRendererServlet -->

        <servlet>

           <servlet-name>ViewRendererServlet</servlet-name>

           <servlet-class>

               org.springframework.web.servlet.ViewRendererServlet

           </servlet-class>

           <load-on-startup>1</load-on-startup>

        </servlet>

        <servlet-mapping>

           <servlet-name>ViewRendererServlet</servlet-name>

           <url-pattern>/WEB-INF/servlet/view</url-pattern>

        </servlet-mapping>

       

        <!-- 設定加載一個PortletServlet, 該配置為Pluto所需-->

        <servlet>

           <servlet-name>SpringTestPortlet1</servlet-name>

           <servlet-class>

               org.apache.pluto.container.driver.PortletServlet

           </servlet-class>

           <init-param>

               <param-name>portlet-name</param-name>

               <param-value>SpringTestPortlet1</param-value>

           </init-param>

           <load-on-startup>1</load-on-startup>

        </servlet>

        <servlet-mapping>

           <servlet-name>SpringTestPortlet1</servlet-name>

           <url-pattern>/PlutoInvoker/SpringTestPortlet1</url-pattern>

        </servlet-mapping>

     <jsp-config>

           <taglib>

               <taglib-uri>http://portals.apache.org/pluto</taglib-uri>

               <taglib-location>/WEB-INF/tld/pluto.tld</taglib-location>

           </taglib>

        </jsp-config>

    4、編輯Portlet.xml文件

     

    <?xml version="1.0" encoding="UTF-8"?>

    <portlet-app

        xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"

        version="2.0" 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">

        <portlet>

           <portlet-name>SpringTestPortlet1</portlet-name>

           <display-name>SpringTestPortlet1</display-name>

           <portlet-class>

               org.springframework.web.portlet.DispatcherPortlet

           </portlet-class>

           <init-param>

               <name>contextConfigLocation</name>

               <value>/WEB-INF/springtest-portlet1.xml</value>

           </init-param>

           <supports>

               <mime-type>text/html</mime-type>

               <portlet-mode>view</portlet-mode>

               <portlet-mode>edit</portlet-mode>

               <portlet-mode>help</portlet-mode>

           </supports>

           <portlet-info>

               <title>SpringTestPortlet1</title>

           </portlet-info>

        </portlet>

    </portlet-app>

    5、編寫相應的Java POJO類、jsp文件、Spring配置文件

    Pojo類在此不再敷述,jsp文件中的開始標簽部分如下:

     

    <%@ page import="javax.portlet.*" contentType="text/html; charset=utf-8" %>

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

    <%@ taglib prefix="portlet" uri="http://java.sun.com/portlet"%>

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

    <portlet:actionURL var="actionURL" />

     

    WEB-INF 下新建 applicationContext.xml 文件,內容如下

     

    <?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.xsd">

        <!-- Default View Resolver -->

        <bean id="viewResolver"

           class="org.springframework.web.servlet.view.InternalResourceViewResolver">

           <property name="viewClass"

               value="org.springframework.web.servlet.view.JstlView" />

           <property name="prefix" value="/WEB-INF/jsp/" />

           <property name="suffix" value=".jsp" />

        </bean>

        <!-- Default ExceptionHandler -->

        <bean id="defaultExceptionHandler"

            class="org.springframework.web.portlet.handler.SimpleMappingExceptionResolver">

           <property name="order" value="10" />

           <property name="defaultErrorView" value="error" />

           <property name="exceptionMappings">

               <props>

                  <prop key="javax.portlet.UnavailableException">

                      unavailable

                  </prop>

                  <prop key="java.lang.Exception">error</prop>

               </props>

           </property>

        </bean>

    </beans>

     

     

    該配置文件中,定義了兩個 Bean。其中第一個 Bean 定義了視圖的默認解析方式,使用 JSP 作為視圖(View),到 /WEB-INF/jsp/ 目錄下尋找 Jsp 文件,并且視圖名稱為 jsp 文件名的前綴。

    在第二個 Bean 中,定義了異常處理方式。如果發生 javax.portlet.UnavailableException 異常,則呈現 unavailable 視圖,即 unavailable.jsp 文件;如果發生其它的 java.lang.Exception 異常,則呈現 error 視圖,即 error.jsp 文件。

    WEB-INF 下新建 PortletSpringTestPortlet1 Spring 上下文配置文件 springtest-portlet1.xml 如下:

     

    <?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.xsd">

        <bean

            class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">

           <property name="portletModeMap">

               <map>

                  <entry key="view" value-ref="viewController" />

               </map>

           </property>

        </bean>

        <bean id="viewController"

           class="org.springframework.web.portlet.mvc.SimpleFormController">

           <property name="commandClass"

               value="springportal.command.AddressBook" />

           <property name="commandName" value="addressBook" />

           <property name="formView" value="addressInput" />

           <property name="successView" value="result" />

        </bean>

    </beans>

     

     

    該上下文根據 Portlet 模式分配控制器,由 Bean 定義可知,僅僅定義了 view 模式的控制器,edit help 模式都沒有進行定義。

    View 模式的控制器 viewController 中,定義了 commandClass commandName 來保存用戶輸入的表單數據,addressInput 視圖(addressInput.jsp)為輸入表單,result 視圖(result.jsp)呈現表單提交結果。

     

    6、遇到的問題

    java.lang.ClassCastException:org.springframework.web.servlet.support.JstlUtils$SpringLocalizationContext

    I had the same issue with Pluto current bundle distribution 1.1.6. The ClassCastException is actually from Pluto's default theme jsp. It's trying to cast a org/springframework/web/servlet/support/JstlUtils$SpringLocalizationContext into a java/lang/String . This is due to that the JSTL implementation doesn't recognize SpringLocalizationContext as a LocalizationContext instance though SpringLocalizationContext surely implements the interface. The root cause is that two classes are loaded from different classloader thus the instanceof check failed.

    Solution: move the jstl-1.0.6.jar and standard-1.0.6.jar under pluto-1.1.6"webapps"pluto"WEB-INF"lib into pluto-1.1.6"shared"lib 

    Note: do not include these 2 jar files in your portlet application (war file).

    ——引自http://forum.springsource.org/showthread.php?t=57816

    解決方法:將pluto-2.0"webapps"pluto"WEB-INF"lib下的jstl.jarstandard.jar移動到pluto-2.0"lib目錄下


    源碼下載地址:點擊下載



    唯美古典的工作室
    posted on 2010-01-14 15:37 唯美古典 閱讀(4171) 評論(0)  編輯  收藏 所屬分類: SSH整合

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费国产真实迷j在线观看| 亚洲AV无码不卡无码| 国产成人精品日本亚洲专区6| 国产成人精品亚洲2020| 日韩在线播放全免费| 亚洲自偷精品视频自拍| 91福利免费体验区观看区| 亚洲AV美女一区二区三区| 99视频在线看观免费| 亚洲视频手机在线| 日本亚洲免费无线码| 亚洲成人在线网站| 日韩免费电影网址| 亚洲精品中文字幕乱码| 99久久免费精品国产72精品九九| 亚洲精品456人成在线| 日韩一级在线播放免费观看| 亚洲国产一区二区三区青草影视| 久久免费精彩视频| 亚洲乱码一二三四区国产| 久久久久国产精品免费网站| 亚洲精品老司机在线观看| 久久免费99精品国产自在现线| 日本xxwwxxww在线视频免费 | 黄网站色在线视频免费观看| 在线亚洲97se亚洲综合在线| 精品国产日韩久久亚洲| 免费特级黄毛片在线成人观看| 特色特黄a毛片高清免费观看| 亚洲av无码一区二区三区网站 | 永久免费不卡在线观看黄网站 | 日韩国产欧美亚洲v片| 日韩版码免费福利视频| 亚洲AV永久无码精品一福利| 国产亚洲精久久久久久无码77777| 久久国产免费一区二区三区| 亚洲欧美一区二区三区日产| 蜜桃视频在线观看免费网址入口| 国产精品亚洲一区二区无码| 国产一区二区视频免费| 日韩a级无码免费视频|