从jsp发送到Java Portlet时,参数未设置

时间:2014-03-24 15:31:27

标签: java jsp liferay portlet

JSP CODE

<script>
    function updateGames() {
        document.getElementById("envSelected").value = "DEV";
        document.getElementById("gameForm").submit();
    }
</script>

<portlet:actionURL name="sampleActionUrl" var="sampleActionUrl">
</portlet:actionURL>

<form id="gameForm" action="${sampleActionUrl}" method="POST">
    <input type="hidden" id="envSelected" name="envSelected">
</form>
<div onClick="updateGames()">CLICK HERE </div>

单击div后,控件将转移到java portlet代码(processAction())

package com.home;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.RenderMode;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class Game extends GenericPortlet {

    @Override
    @RenderMode(name = "VIEW")
    protected void doView(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        response.setContentType(request.getResponseContentType());
        PortletContext context = getPortletContext();
        PortletRequestDispatcher rd = context
                .getRequestDispatcher("/WEB-INF/jsp/game.jsp");
        String env = request.getParameter("envSelected");
        System.out.println("Game.doView() >> rendering with env : " + env);
        rd.include(request, response);
    }

    @Override
    public void processAction(ActionRequest request, ActionResponse response)
            throws PortletException, IOException {
        String env = request.getParameter("envSelected");
        System.out.println("Game.processAction() >> processAction for envSelected: " + env);
    }
}

我试图打印我在jsp代码中设置的参数的值。它打印为 null

有人可以指导我这里可能缺少的东西吗?

1 个答案:

答案 0 :(得分:1)

我怀疑它与命名间距参数有关。

JSR 286 compliant namespace parameter

如果这对您没有帮助,请尝试打印请求中的所有参数,以查看您的参数是否存在于您不期望的名称下。