在jsp中如何用request中获取后台传来的数据?

2024-12-11 00:22:17
推荐回答(4个)
回答(1):

  • 用request.getAttribute获取,而不是getParameter。

  • HttpServletRequest接口有setAttribute方法,而没有setParameter方法

  • 当两个Web组件之间为链接关系时,被链接的组件通过getParameter方法来获得请求参数

  • String datetime1 = (String)request.getAttribute("datetime");

  • 通常情况下,你每次提交(点击搜索)的时候,

  • 过程如下: 转到后台,根据你的输入生成新的sql语句转到后台

  • 数据库查询出新的表格内容

  • 转到前台展示整个页面

  • 到了展示的这一步,会生成新的页面,虽然是跟上一个一样的页面,其实他的内容都是重新生成显示的.

回答(2):

你用的是request.setAttribute("datetime", datetime);设置的值,所以对应的应该用request.getAttribute("datetime");来取值.

request.getParameter("datetime");顾名思义,是当你用参数的方式通过url或表单将datetime传递从一个页面传递到另一个页面或action时,在目的地采用request.getParameter("datetime")获取传过来的参数值

回答(3):

用request.getAttribute获取,而不是getParameter。
(1)HttpServletRequest接口有setAttribute()方法,而没有setParameter()方法
(2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,

String datetime1 = (String)request.getAttribute("datetime");

回答(4):

用request.getAttribute获取,而不是getParameter。