<bean id="testController" name="/hello.do" class="com.rl.controller.TestController" /> <!-- 定义视图解析器 --> <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> <!-- 通过:http://localhost:8080/springmvc/hello1.do可以访问 --> <prop key="/hello1.do">testController</prop> <!-- 通过:http://localhost:8080/springmvc/toIndexBean.do可以访问 --> <prop key="/toIndexBean.do">toIndexBean</prop> </props> </property> </bean>public class TestController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception { System.out.println("hello springmvc"); //视图解析器在解析ModelAndView的时候会自动追加前缀和后缀, //如果视图解析器的前缀下依然有目录结构,在ModelAndView中 //来指定前缀和后缀直接的一段路径 return new ModelAndView("jsp1/index"); }}也可以继承Controller接口
新闻热点
疑难解答