ciao!
sto cercando di usare i controller con le annotations.
questo il controller:
questo il dispatcher-servlet.xmlcodice:@Controller @RequestMapping("/") public class IndexController { @RequestMapping(method = RequestMethod.GET) public ModelAndView helloWorld(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("index"); model.addObject("msg", "hello world"); return model; } }
e infine l'applicationContext.xml:codice:<?xml version='1.0' encoding='UTF-8' ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
nel web.xml ho messo così:codice:<?xml version='1.0' encoding='UTF-8' ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <context:component-scan base-package="com.mp" /> </beans>
ma ottengo sempre un HTTP Status 400.codice:<listener> <!--<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>--> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
da cosa può dipendere??

Rispondi quotando