我用velocity时,在dispatch-servlet中配置
<bean id="viewResolver"  class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"><property name="exposeRequestAttributes" value="true"></property>
<property name="exposeSessionAttributes" value="true"></property>可以访问到request和session

解决方案 »

  1.   

    谢谢ilysony ,我的意思是这样的,在controller里,假如我extends MultiActionController,在test(request,response)方法中,我需要像jsp里那样调用servlet.getServletContext()类似的方法。在jsp或者struts里可以直接用servlet,但是在springMVC里不行,我想知道怎样才能掉出servlet对象。
      

  2.   

    request.getSession().getServletContext()?
      

  3.   

    servlet 对象?用request请求作用域?
      

  4.   

    ActionContext ac=ActionContext.getContext();
    然后Session,request随便你用了
    import com.opensymphony.xwork2.ActionContext;
    倒的是这个包,别倒错了
      

  5.   

    看错了,我说的是Struts2的获取方法....
      

  6.   

    楼主似乎是误会了;
    Action.getServlet();
    得到的Servlet是ActionServlet,也就是说他并非单纯的Servlet;
    相反的,如果用springMVC来得到Servlet的功能,一般可以使用:
    req.getSession().getServletContext();
    得到的ServletContext基本可以完成任何的Servlet的功能;