action class do not passing objects to jsp class ,

2019-03-01 05:41发布

问题:

i'm using struts2 in liferay to create a portlet, i have a submit button that doing an action, in action method i want to fill a private field and pass it to resualt add.jsp but when i want to print that field in add.jsp the value is null. what is the problem???!!! what should i do????!!

there is no error or exception during run server,build/deploy and executing...

here is my code:

portlet.xml

http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">

    <description xml:lang="EN">IIN Subject</description>

    <portlet-name>MySiteStruts</portlet-name>
    <display-name>MySiteStruts</display-name>
    <!-- struts portlet class -->
    <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
    <!-- The namespace for the actions configured for view mode -->
    <init-param>
        <name>viewNamespace</name>
        <value>/support</value>
    </init-param>

    <!-- The default action to invoke in view mode. -->
    <init-param>
        <name>defaultViewAction</name>
        <value>index</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
        <mime-type>text/html</mime-type>
    </supports>
    <portlet-info>
        <title>MySiteStruts</title>
        <short-title>MySiteStruts</short-title>
        <keywords>MySiteStruts</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>

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.devMode" value="true" />

    <package namespace="/support" extends="struts-portlet-default,json-default"
        name="subjectview">

        <interceptors>
            <interceptor-stack name="storeStack">
                <interceptor-ref name="defaultStack" />
                <interceptor-ref name="store">
                    <param name="operationMode">STORE</param>
                </interceptor-ref>
            </interceptor-stack>
            <interceptor-stack name="retrieveStack">
                <interceptor-ref name="defaultStack" />
                <interceptor-ref name="store">
                    <param name="operationMode">RETRIEVE</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <action name="index" >
            <result>/html/support/view.jsp</result>
        </action>


        <action name="addsubjects" class="com.test.actions.PowerAction"
            method="navigateToAddSubject">
            <result name="success">/html/support/add.jsp</result>
        </action>

    </package>
</struts>

PowerAction.java

package com.test.actions;

import com.opensymphony.xwork2.ActionSupport;

public class PowerAction extends ActionSupport {

    private String testString;

    @Override
    public String execute() throws Exception {

        return "success";
    }
    public String navigateToAddSubject(){

        testString = "test object value!!!!!";
        System.out.println(testString);
        return SUCCESS;
    }
    public String getTestString() {
        return testString;
    }
    public void setTestString(String testString) {
        this.testString = testString;
    }
}

view.jsp

<%@ include file="/html/init.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:form action="addsubjects" theme="simple">
         <s:submit value="submit"/>
</s:
[/code]

[b]add.jsp[/b]
[code]
<%@ include file="/html/init.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<h1>print str:<br></h1>
<h2><s:property value="%{testString}"/></h2>

i even use value="testString" in add.jsp but not working too.