SpringMVC
<context:component-scan base-package="cn.wwy.controller"></context:component-scan> <!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <mvc:resources mapping="/img/**" location="/img/"></mvc:resources> <!--前端控制器--> <bean id="firts" class="cn.wwy.controller.SpringMVC"></bean> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean> <!--处理映射器的第二种实现--> <!-- <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/hello.do">firts</prop> <prop key="/firts.do">firts</prop> </props> </property> </bean>--> <!--处理映射器的第二种实现--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="UrlMap"> <map> <entry key="/hello.do" value="firts"></entry> </map> </property> </bean> <!--拦截器--> <!-- <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="cn.wwy.interceptor.MyIntercptor"></bean> </mvc:interceptor> </mvc:interceptors>--> </beans>
public class SpringMVC implements Controller { public ModelAndView handleRequest(HttpServletRequest Request, HttpServletResponse Response) throws Exception { ModelAndView mv=new ModelAndView(); mv.addObject("msg","wwy"); mv.setViewName("index"); return mv; } }