gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:05:20 25 4
gpt4 key购买 nike

JSP代码

<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

有人可以指导我在这里可能缺少什么吗?

最佳答案

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

JSR 286 compliant namespace parameter

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

关于java - 从 jsp 发送到 Java Portlet 时未设置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22613748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com