Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlet中request.setAttribute()设置的值不能由JSP中的request.getParameter()访问_Jsp_Servlets_Parameters_Attributes_Parameter Passing - Fatal编程技术网

Servlet中request.setAttribute()设置的值不能由JSP中的request.getParameter()访问

Servlet中request.setAttribute()设置的值不能由JSP中的request.getParameter()访问,jsp,servlets,parameters,attributes,parameter-passing,Jsp,Servlets,Parameters,Attributes,Parameter Passing,我支持在点击表单按钮后向控制器servlet发送请求,它需要检查用户是否登录以及按下了哪个按钮 第一部分工作正常,但当我尝试将结果设置为参数并将请求转发到JSP页面时,参数“Button”总是返回null。 有人能帮我理解为什么会这样吗?也许有更好的办法 Servlet: request.setAttribute("Buttons", "Add a new coupon"); request.getRequestDispatcher("/admin_main.jsp").forward(requ

我支持在点击表单按钮后向控制器servlet发送请求,它需要检查用户是否登录以及按下了哪个按钮

第一部分工作正常,但当我尝试将结果设置为参数并将请求转发到JSP页面时,参数“Button”总是返回null。 有人能帮我理解为什么会这样吗?也许有更好的办法

Servlet:

request.setAttribute("Buttons", "Add a new coupon");
request.getRequestDispatcher("/admin_main.jsp").forward(request,response);
JSP:

if(request.getAttribute(“按钮”)!=null)
将起作用

信息:

始终执行
request.getParameter()
提取请求参数(即通过发布html表单发送的数据)。
request.getParameter()
始终返回字符串值,数据来自客户端

始终使用
request.getAttribute()
将对象添加到服务器端的请求作用域,即使用
request.setAttribute()

如果(request.getAttribute(“按钮”)!=null)
将起作用

信息:

始终执行
request.getParameter()
提取请求参数(即通过发布html表单发送的数据)。
request.getParameter()
始终返回字符串值,数据来自客户端


始终使用
request.getAttribute()
将对象添加到服务器端的请求范围,即使用
request.setAttribute()

您应该显示一些代码,以便可以进行错误跟踪。请,请,请,请,请,请阅读JSP EL,也许可以找到1999年没有编写的JSP教程。(我很感激这说起来容易做起来难。)虽然可以做到,但JSP今天并不是这样做的。没有理由这么做。这本书其实还不错。感谢书籍链接…我开始阅读它,但对于课程项目,我做事情的方式将不得不做…相关:你应该显示一些代码,以便可以进行错误跟踪。请,请,请,请,请阅读JSP EL,也许可以找到一个1999年没有编写的JSP教程。(我很感激这说起来容易做起来难。)虽然可以做到,但JSP今天并不是这样做的。没有理由这么做。这本书其实还不错。谢谢你的书链接…我开始阅读它,但对于课程项目,我做事情的方式将不得不做…相关:谢谢,它完美地解决了我的问题:)谢谢,它完美地解决了我的问题:)
if (request.getParameter("Buttons") != null) {
    // ...
}