1. 伪静态化
为了迎合搜索引擎的排名规则
web.xml
<!-- springmvc的前端控制器 -->
<servlet>
<servlet-name>e3-portal-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>e3-portal-web</servlet-name>
<!-- 伪静态化 -->
<url-pattern>*.html</url-pattern>
</servlet-mapping>
2. 拦截配置,不需要输入后缀,访问首页
配置web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- springmvc的前端控制器 -->
<servlet>
<servlet-name>e3-portal-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>e3-portal-web</servlet-name>
<!-- 伪静态化 -->
<url-pattern>*.html</url-pattern>
</servlet-mapping>
创建IndexController
@Controller
public class IndexController {
@RequestMapping("/index")
public String showIndex(Model model) {
return "index";
}
}
这样就可以直接通过主域名直接访问到首页,例如http://jd.com