无法使用action chan和post param重定向到另一个url

时间:2017-11-29 10:24:08

标签: struts2

尝试使用post参数重定向到外部网址。  我的代码在下面

 <action name="testit" class="TestAction" method="test">
            <result name = "success" type = "chain">
                <param name="location">${at.url}</param>
                <param name="login">${at.login}</param>
                <param name="pass">${at.pass}</param>
            </result>
</action>

动作类中的方法是

public String test(){
at.setUrl("http://www.test.com");
 at.setLogin("ssfd");
  at.setPass("ssfd");
}

我正面临follong错误

Info:   2017-11-29 15:23:39 ERROR Dispatcher:38 - Exception occurred during processing request: null
java.lang.NullPointerException
    at com.opensymphony.xwork2.util.OgnlTextParser.evaluate(OgnlTextParser.java:22)
    at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:170)
    at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:127)
    at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:49)
    at com.opensymphony.xwork2.ActionChainResult.execute(ActionChainResult.java:207)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

chain结果类型没有重定向。而是使用redirect结果类型。

<action name="testit" class="TestAction" method="test">
        <result name = "success" type = "redirect">
            <param name="location">${at.url}</param>
            <param name="login">${at.login}</param>
            <param name="pass">${at.pass}</param>
        </result>
</action>