【问题标题】:ATG - session or request attribute coming as null when checkFormRedirect is calledATG - 调用 checkFormRedirect 时会话或请求属性为空
【发布时间】:2019-01-31 07:54:43
【问题描述】:

在我的 ATG 应用程序中,当我使用 checkFormRedirect 将用户重定向到带有一些参数的 jsp 页面时,我得到的参数为空。请看下面的 FormHandler 代码:

用户表单处理程序:

public boolean handleUserRedirect(dynamo req, dynamo res){

//using request
req.setParameter("test", "testdata");

//using session
HttpSession session=req.getSession();  
session.setAttribute("uname","testdata"); 

//redirect to test.jsp
return checkFormRedirect("/test/test.jsp","null",req,res);
}

test.jsp:

<% out.println(session.getAttribute("uname")); %>

<% String stErrorMsg=(String)session.getAttribute("uname");%>

<%=stErrorMsg %>

<% request.getParameter("test")%>

另外,我尝试在我的 formHandler 中使用变量并设置值,但我仍然将值设为 null。可以帮忙吗?

【问题讨论】:

    标签: atg atg-dynamo oracle-commerce droplet atg-droplet


    【解决方案1】:

    通常,您不能使用 sendRedirect() 方法发送 POST 请求。您可以使用 RequestDispatcher 在相同的 Web 应用程序、相同的上下文中转发()带有参数的请求。

    RequestDispatcher dispatcher = servletContext().getRequestDispatcher("test.jsp");
    dispatcher.forward(request, response);
    

    HTTP 规范 规定所有重定向都必须采用 GET(或 HEAD) 的形式。如果安全是一个问题,您可以考虑加密您的查询字符串参数。另一种方法是您可以通过使用 POST 方法的隐藏表单并在页面加载时使用 javascript 提交来向目标 POST。

    所以你可以使用Session方法:我试过我在JSP中得到了值。

    <%
          out.println(session.getAttribute("message"));
          session.removeAttribute("message");
    %>
    /* Or using JSTL */
      <c:out value="${sessionScope.message}" />
      <c:remove var="message" scope="session" />
    

    截图

    希望对您有所帮助。

    【讨论】:

    • 是的,我做了同样的方法,只是我没有在会话中保存值,而是在处理程序本身中添加并在 jsp 中访问。谢谢你的帮助。有没有其他方法可以直接从服务器发布请求而不是重定向到前端。
    • @MananKapoor 目前尚不清楚您想要实现什么。如果您正在调用一些网络服务,如果是这样,那么您可以使用 httpclient 等。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 2015-10-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    相关资源
    最近更新 更多