index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <html> <body> <h2>Hello World!</h2> <a href="account/findAll">测试查询</a> </body> </html>
list.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>用户请求</title> </head> <body> <h3>查询所有用户信息</h3> </body> </html>
controller:
@Controller @RequestMapping("/account") public class AccountController { @RequestMapping("/findAll") public String findAll(){ System.out.println("表现层:查询所有账户。。。"); return "list"; } }
web.xml
<servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param>
springmvc.xml:
<!--配置的视图解析器对象--> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/> </bean> <!--过滤静态资源--> <mvc:resources location="/css/" mapping="/css/**" /> <mvc:resources location="/images/" mapping="/images/**" /> <mvc:resources location="/js/" mapping="/js/**" /> <!--开启SpringMVC注解的支持--> <mvc:annotation-driven/>
首先你先测试一下,是否进入了控制层的那个findAll方法,我感觉你没有进去这个方法。