【问题标题】:httpServletRequest.getParameter returns nullhttpServletRequest.getParameter 返回 null
【发布时间】:2014-07-09 05:49:16
【问题描述】:

我有两台服务器,一台(本地)和另一台(通过 vpn 远程调用)。

在两者上都部署了相同的应用程序。

我停止vpn调用本地的,所以它们之间没有干扰。

我试图在 doFilter 方法中获取 servletFilter 中的参数。

本地在我的电脑上:weblogic server 11g
远程是通过vpn:weblogic 企业管理器

在第一种情况下,httpServletRequest.getParameter 返回 post 请求的预期值。

在第二个中得到 null。

我发送到以下网址:

http://mydomain/myapp/faces/login-return.jspx

发送请求的html表单:

<html>

    <body>
          <form  action="https://mydomain/myapp/faces/login-return.jspx"  method="post">
            <input type="hidden" name="param1" value="value1"  />
            <input type="hidden" name="param2" value="value2"  />
            <input type="submit" name="submit" value="Send to server" />
        </form>
    </body>
</html> 

我的 servlet 过滤器中的代码:

    if (isSessionControlRequiredForThisResource(httpServletRequest, getLoginPage())) {

        if(httpServletRequest.getParameter("param1") != null) {
            httpServletRequest.getSession().setAttribute("param1", httpServletRequest.getParameter("param1"));

        }

任何帮助都会被批准

【问题讨论】:

  • 您是否添加了一些日志消息以确保它不会是 isSessionControlRequiredForThisResource 返回 false 的副作用?
  • 也许你在第二种情况下提出了跨域请求? (从代码中不清楚)我不确定,但这可能是参数为空的原因(见link
  • @SergeBallesta 怎么可能是 isSessionControlRequiredForThisResource 的副作用?
  • @Den 提出跨域请求是什么意思?
  • @GingerHead If isSessioncontrolrequiredforthisresource retiens fasse 你的代码永远不会被调用并且你的会话参数 romains 为空。

标签: java servlets servlet-filters weblogic11g oracle-enterprise-manager


【解决方案1】:
 @PostMapping("/cookies")
func(HttpServletRequest request) {

        Cookie[] cookies = request.getCookies();
        
         if (cookies != null) {
            //ive goten always null
         }

   }

“PostMapping(“/cookies”)”上方的错误将其更改为“GetMapping(“/cookies”)”,一切都开始工作了。 它的`导致 func 无法在没有任何主体的情况下读取 post hhtp 请求中的 cookie,如果你没有向后端发送任何数据而不是使用 get 方法 insted。

【讨论】:

    【解决方案2】:

    问题在于,服务器期待的是 https 调用,而不是 http

    因此,当我将调用协议更改为 https 时,它开始像魅力一样收集请求参数!

    【讨论】:

    • 换句话说,当您说您正在“发送到以下 URL:https://...”,并且您有 'action="https://..."' 时,您不是,你也没有。很难看出仅此一项会导致这个问题。这听起来更像是您的重定向不正确。
    • @EJP 是的,这是一个错字,我发送的是 http。本地服务器没问题,但企业经理期待 https(它是这样配置的)。它正常响应 http 调用,但通过 https 响应,很奇怪吗?
    • @EJP 但这是 FacesServlet 的正常行为吗?
    猜你喜欢
    • 2016-03-28
    • 2021-11-20
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 2019-08-21
    相关资源
    最近更新 更多