主页面basePath
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
跳转到Controller的方法
<li><a href="${basePath}/bj/list.do" target="right">班级管理</a></li>
<li><a href="${basePath}/student/list.do" target="right">学生管理</a></li>
加 .do是因为
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
控制层用的注解
@Controller
@RequestMapping("/bj")
@RequestMapping("/list")
控制层返回
return "bj/edit";
前提是配置好spring-mvc.xml,即配置好前缀和后缀
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/WEB-INF/jsp/" /> -->
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
<!-- <property name="prefix" value="" />
<property name="suffix" value=""></property> -->
</bean>