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 。
有人可以指导我这里可能缺少的东西吗?
答案 0 :(得分:1)