【问题标题】:Ajax call using XmlHttp to struts getting null values in request parameter in jboss server使用 XmlHttp 的 Ajax 调用 struts 在 jboss 服务器的请求参数中获取空值
【发布时间】:2014-09-14 11:39:09
【问题描述】:

我对这个问题感到困惑。实际上我的代码在 weblogic 服务器中运行良好,但是当我尝试使用 jboss5 服务器时,它不起作用。请帮我解决这个问题。

我的问题是,我正在使用 XmlHttp 从 ajax 脚本调用一个 struts 动作并传递一些参数。当我尝试检索 struts 动作类中的参数时,它返回空值。

这是我的代码: Ajax 脚本:

var params = (inpVal != '' && outVal != '' && oprAction != '') ? 'inReturn='+tmpStr+'&ouReturn='+outVal+'&Operation_Scr='+oprAction : null;

XmlHttp.onreadystatechange = HandleResponseFromServer;
        XmlHttp.open("POST", sUrl,  true);
        XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");
        XmlHttp.send(params);

如果我在这里打印参数,每个值都是完美的。 struts 配置:

 <action  path="/ajax-action"
            type="com.amgen.devis.gmat.util.AjaxAction"
            name="StudyDesignAssignmentForm" input="/mainCDM.jsp" scope="request" validate="false">
              <forward name="success"  path="/content/AjaxOutPut.jsp" contextRelative="true"/>
 </action>

还有我的动作课: 如果我在这里打印出现空值

System.out.println("Operation Type:  "+(String)request.getParameter("Operation_Scr"));

返回空值。

请帮助我。

【问题讨论】:

  • 你为什么要设置Content-Type两次?为什么不离开application/x-www-form-urlencoded 并测试它是否有效?
  • 感谢@Buhake sindi,现在可以正常工作了。

标签: ajax jboss5.x struts-1


【解决方案1】:

您在 HTTP 请求标头上设置了两次 Content-Type。这实质上是用它收到的最后一个值覆盖Content-Type

解决方案是使用如下设置您的Content-Type

XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-9");
XmlHttp.send(params);

请注意,我已将charset 包含在参数值中。

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2013-12-14
    • 1970-01-01
    • 2014-01-12
    • 2019-07-09
    • 2011-06-24
    • 2021-12-12
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多