Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: HttpServletResponse in spring controller

  1. #1
    Join Date
    Apr 2010
    Posts
    10

    Default HttpServletResponse in spring controller

    hello,

    how can we access to "HttpServletResponse" in a spring controller ?

    François

  2. #2
    Join Date
    Mar 2007
    Posts
    128

    Default

    If you're using @Controller and @RequestMapping, you should be able to define it in your method's arguments. I've never done it, but it should work - you'll probably want your method to return void since you're handling the response that way.

    Code:
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public void home(Model model, HttpServletResponse response) {
    ...
    }
    In the Spring Framework Reference pdf, search for "Defining @RequestMapping handler methods"

  3. #3
    Join Date
    Mar 2011
    Location
    Washington, DC
    Posts
    60

    Default

    Have you try this and see if this work?
    Code:
     
    @RequestMapping(method = RequestMethod.POST)
    public void submitForm(@ModelAttribute("test") TestDTO command,BindingResult result,ModelMap modelMap, SessionStatus status,HttpServletRequest request, HttpServletResponse response ) throws ServletRequestBindingException

  4. #4
    Join Date
    Apr 2010
    Posts
    10

    Default

    thank you for the answer but i can't use @Controller and @RequestMapping in my controller

    I have the message "the annotation @Controller is disallowed for this location".

  5. #5
    Join Date
    Mar 2007
    Posts
    128

    Default

    What version of Spring are you using? Can you post some code?

  6. #6
    Join Date
    Apr 2010
    Posts
    10

    Default

    i am using spring version=2.5.5

    My controller :
    Code:
    public class AdminListeInscritController extends CommonController implements Serializable  {
        ...
        public AdminListeInscritController() {}
        ...
        @RequestMapping(value = "/", method = RequestMethod.GET)
        public void home(Model model, HttpServletResponse response) {
          ...
        }
        ...
      }
    @RequestMapping generates this error message : "RequestMapping cannot be resolved to a type"

  7. #7
    Join Date
    Apr 2006
    Posts
    166

    Default

    Can you do this

    @Controller
    public class AdminListeInscritController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    ......

  8. #8
    Join Date
    Apr 2010
    Posts
    10

    Default

    When i do that i have the message "@Controller cannot be resolved to a type"

  9. #9
    Join Date
    Apr 2006
    Posts
    166

    Default

    Is that bean created after the application re-start? (using log to check)
    You may need to have
    <context:component-scan base-package="location.of.your.controller" />
    or declare that bean in app-servlet.xml
    Do you import this:
    import org.springframework.stereotype.Controller;

  10. #10
    Join Date
    Apr 2010
    Posts
    10

    Default

    the controller is created in the springConfiguration.xml file

    Code:
    <bean id="adminListeInscritController" class="fr.univNantes.sig.certif.controller.AdminListeInscritController" scope="request" parent="factorisationController">
    		<constructor-arg>
    			<ref bean="accesService"/>
    		</constructor-arg>
    </bean>
    In the controller i solved the first error "Controller cannot be resolved to a type" by importing org.springframework.stereotype.Controller
    But when i try to add the statment @RequestMapping(value = "/", method = RequestMethod.GET) i still have this error : "RequestMapping cannot be resolved to a type"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •