2013-06-13 4 views
2

,하는 doView()가 I가 링크를 포함하는 간단한 JSP를 표시 할 수있어 WebSphere Portal에 7에서 실행 호출되지 작동하지하는 액션을 호출하고 입력을 받아들이는 다른 JSP를 표시합니다. 그건 잘 작동합니다.스트럿츠 2 포틀릿 - redirectAction 나는 간단한 스트럿츠 2 JSR 286 포틀릿을 만들려고 해요

그러나 redirectAction을 사용하려고하면 문제가 발생하기 시작합니다. 오류 메시지가 표시되지 않지만 리디렉션이 작동하지 않는 것 같습니다. 포틀릿에는 빈 페이지가 표시됩니다.

이 디버깅에서 나는 포틀릿 클래스의 doView 메서드가 호출되지 않는다는 것을 알아 차렸는데, 이는 매우 의심스러워 보입니다. 사람이 경험은 WebSphere Portal에 스트럿츠 2 개 포틀릿을 개발하고있는 경우

, 내 설정 파일이 올바른지 확인에 약간의 도움을 주셔서 감사합니다. 내가 놓친 게 있니?

WebSphere Portal 7.0.0.2 
WebSphere Application Server 7.0.0.25 
RAD 8.0.4 
Struts 2.3.14.2 
Windows 7 

은 portlet.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<portlet-app id="com.ibm.demo.jsr286.TopUpPortlet.72594d5fe3" 
version="2.0" 
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"> 
<portlet> 
    <description xml:lang="EN">Demo JSR 286 Struts Portlet</description> 
    <portlet-name>Demo Portlet</portlet-name> 
    <display-name>Demo Portlet</display-name> 

    <!-- DemoPortlet extends org.apache.struts2.portlet.dispatcher.Jsr286Dispatcher --> 
    <portlet-class>com.demo.jsr286.DemoPortlet</portlet-class> 

    <init-param> 
     <name>viewNamespace</name> 
     <value>/view</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> 

    <supported-locale>en</supported-locale> 

    <portlet-info> 
     <title>Demo Portlet</title> 
     <short-title>DemoPortlet</short-title> 
     <keywords>Demo Portlet</keywords> 
    </portlet-info> 

</portlet> 

<default-namespace>http://JSR286StrutsDemo/</default-namespace> 
</portlet-app> 

의 web.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" 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"> 

<display-name>JSR 286 Struts Demo</display-name> 

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

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

</web-app> 

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> 
<include file="struts-plugin.xml"/> 

<package name="view" extends="struts-portlet-default" namespace="/view"> 

    <!-- This action works -->  
    <action name="index"> 
     <result>/html/view/index.jsp</result> 
    </action> 

    <!-- This action works --> 
    <action name="startDemo"> 
     <result>/html/view/demo.jsp</result> 
    </action> 

      <!-- This action does not work --> 
    <action name="redirectToIndex"> 
     <result type="redirectAction"> 
      <param name="actionName">index</param> 
      <param name="namespace">/view</param> 
      <param name="portletMode">view</param> 
     </result> 
    </action> 

</package> 

</struts> 
여기

은 세부 사항입니다

* 업데이트 *

문제가 다소 좁혀졌습니다. 액션이 struts 액션이 아닌 파일 위치로 해석되는 것 같습니다. 그래서 "redirectToIndex"액션을 호출하면 "/view/index.action"이라는 페이지를 표시하려고 시도합니다. 해당 경로가있는 파일을 작성하여이 사실을 확인 했으므로 해당 파일의 내용이 포틀릿에 표시됩니다.

는 내가 아마 몇 가지 구성 옵션을 누락 느낌,하지만 난 모르겠어요. 서블릿 필터가 어쩌면? 누구든지 도와 줄 수 있습니까?

+0

그래서 무엇입니까? 리디렉션이 작동하지 않거나 메서드가 호출되지 않습니다? BTW 왜'struts-plugin.xml' 파일을 포함하고 있습니까? –

+0

둘 다 정말입니다. 리디렉션이 작동하지 않는 것이 첫 번째 문제였습니다. 그런 다음 조사 할 때 doView가 호출되지 않는 것으로 나타났습니다. struts-plugin.xml은 struts-portlet-default 패키지가 정의 된 곳이기 때문에 포함하고 있습니다. 그게 맞지 않아? – dgwatson

+0

이미 포함되어 있으므로 직접 포함시킬 필요가 없습니다. 액션 클래스를 사용하여'redirectToIndex' 액션 정의에 클래스 속성을 부여하십시오. –

답변

1

실제로 Jsr286Dispatcher은 운영자이므로 doView 메서드가 필요하지 않습니다. 일반 Struts2 응용 프로그램과 같은 동작을 사용할 수 있습니다. 문서에서

:

포틀릿 수준의 요소는 항상 org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher (또는 서브 클래스, 당신은 일부 사용자 지정 기능을 추가 한 경우). 이것은 Struts 2 프레임 워크의 디스패처 역할을하는 포틀릿이며 들어오는 사용자 상호 작용을 Struts 2가 이해하는 액션 요청으로 변환합니다. jsr286 사양 <portlet-class>에 대한

는 Struts2 액션을 호출합니다 org.apache.struts2.portlet.dispatcher.Jsr286DispatcherdefaultViewAction 초기화-PARAM해야한다. 그리고 보통 struts.xml 파일에서 action class + method를 호출하여 정의 할 수 있습니다.

Jsr286Dispatcher<portlet-class>으로 정의하고 struts.xml 작업 정의에 사용할 작업을 만들어야합니다.

http://struts.apache.org/development/2.x/docs/struts-2-portlet-tutorial.htmlhttp://struts.apache.org/development/2.x/docs/portlet-plugin.html 링크도 참조하십시오.

+0

도움 주셔서 감사합니다, 알렉산드르. 대단히 감사합니다. 리디렉션하려는 작업 (/view/index.action)이 struts 작업이 아닌 파일 위치로 해석되고 있음을 발견했습니다. 나는 원래의 게시물을 그 정보로 업데이트했다. 액션이 액션으로 취급되도록하는 방법을 잘 모르겠습니다. 어떤 아이디어? – dgwatson

+0

'DemoPortlet '대신'Jsr286Dispatcher'를 사용하고 있습니까? 또한'FilterDispatcher'가 web.xml에 필요하다고 생각하지 않습니다. –