页面:request.setAttribute("prodcut","1234142143123");
<a href="<%=basePath %>/thisisademo">
java:@RequestMapping("/thisisademo")
public String addProduct(HttpServletRequest request, HttpServletResponse response){
           System.out.println(request.getAttribute("product"));
         }为什么控制台打出来为null值呢。
web.xml文件中加入了。
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>请帮忙看看,谢谢了。

解决方案 »

  1.   

    request.getSession().getAttribute("product");
      

  2.   

    谢谢cbxjj的回答,可还是有点不清楚。
    为什么啊,我是放到request中的了,那要是传个对象过来,也得去session中取啊?
      

  3.   

    用session试试呢?有可能是request被重新定义。清空了里面的值。而且页面向controller传数据,也可以放到url里面或action里。直接request.getParameter("prodcut");就能取到
      

  4.   

    谢谢javaylj的回答,我用request.getParameter("product")取值也为空。
    request.getSession().getAttribute("product");也为空。
    说明一下“product”的名字前台都一致的。不是因为这个字写错了。
      

  5.   

    request.setAttribute("prodcut","1234142143123");
    改成
    request.getSession().setAttribute("prodcut","1234142143123");
    还有你的页面
    页面:request.setAttribute("prodcut","1234142143123");
    <a href="<%=basePath %>/thisisademo">
    这里的request.setAttribute("prodcut","1234142143123");来添加一个属性,那么你<a href="<%=basePath %>/thisisademo">能把这个属性传过去吗??反正我觉得是传不过去的
      

  6.   

    你前台是用什么方式跳转到后台的?没见过前台request.setAttribute后台能接收的
    反过来可以
    前台到后台最好走url后面接或者隐藏表单都可以
      

  7.   

    <a href="<%=basePath %>/thisisademo?product=123412341234">
      

  8.   

    第一个:要是想用session取值。那在页面也要把值放到session中。
    在页面里request.getSession().setAttribute("prodcut","1111");
    然后在controller里request.getSession().getAttribute("prodcut");
    第二个:要是想用request.getParameter("prodcut");取值。那楼主要确认一下参数是否在url或action里。如:
    <form metod="post" action=".....? prodcut="+ prodcut+" >类似这种的。
      

  9.   

    好是这样的,后台不能通过request.getArribute("");但要是要在request里放个对象该怎么放啊。
    我能想到的只有request.getAttribute();方法来取。
      

  10.   

    在前台向后台传数据一般是不用setAttribute()这种方式,一般都是在action里传一个参数。在后台用request.getParameter()取。要是实在想用setAttribute()应该也是能实现的。但最好用session传值。因为request跳转界面时,会被重置。贴的代码有点少,不知道那儿出问题了。
      

  11.   

    ActionContex 对象为空怎么回事