hello,
how can we access to "HttpServletResponse" in a spring controller ?
François
hello,
how can we access to "HttpServletResponse" in a spring controller ?
François
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.
In the Spring Framework Reference pdf, search for "Defining @RequestMapping handler methods"Code:@RequestMapping(value = "/", method = RequestMethod.GET) public void home(Model model, HttpServletResponse response) { ... }
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
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".
What version of Spring are you using? Can you post some code?
i am using spring version=2.5.5
My controller :
@RequestMapping generates this error message : "RequestMapping cannot be resolved to a type"Code:public class AdminListeInscritController extends CommonController implements Serializable { ... public AdminListeInscritController() {} ... @RequestMapping(value = "/", method = RequestMethod.GET) public void home(Model model, HttpServletResponse response) { ... } ... }
Can you do this
@Controller
public class AdminListeInscritController {
@RequestMapping(value = "/", method = RequestMethod.GET)
......
When i do that i have the message "@Controller cannot be resolved to a type"![]()
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;
the controller is created in the springConfiguration.xml file
In the controller i solved the first error "Controller cannot be resolved to a type" by importing org.springframework.stereotype.ControllerCode:<bean id="adminListeInscritController" class="fr.univNantes.sig.certif.controller.AdminListeInscritController" scope="request" parent="factorisationController"> <constructor-arg> <ref bean="accesService"/> </constructor-arg> </bean>
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"