简体   繁体   English

请求属性在从一个 Servlet 转发到另一个 Servlet 的过程中丢失

[英]Request Attributes are lost during forwarding from one Servlet to another Servlet

In my web application I have 2 servlets where one pass data to another.在我的 Web 应用程序中,我有 2 个servlets ,其中一个将数据传递给另一个。 Please check the below code.请检查以下代码。

RequestDispatcher requestDispatcher = request.getRequestDispatcher("LoadCategoryList");
            request.setAttribute("save_result", result);
            requestDispatcher.forward(request, response);

In this code I am passing data save_result to LoadCategoryList .在这段代码中,我将数据save_result传递给LoadCategoryList Below is how I try to collect this data in LoadCategoryList下面是我尝试在LoadCategoryList收集这些数据的LoadCategoryList

String result = request.getParameter("save_result");

Anyway, the passed data seems to be NULL .无论如何,传递的数据似乎是NULL But I can GUARANTEE that data I am passing are not NULL .但我可以保证我传递的数据不是NULL What's wrong here?这里有什么问题?

Request parameters and request attributes are two different things.请求参数和请求属性是两个不同的东西。

If you set a value using ServletRequest.setAttribute() , you have to retrieve it using ServletRequest.getAttribute() .如果使用ServletRequest.setAttribute()设置值,则必须使用ServletRequest.getAttribute()检索它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM