WebController.java
package com.yiibai.springmvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class WebController {
@RequestMapping(value="/index",method=RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(value="/staticPage",method=RequestMethod.GET)
public String redirect(){
return "redirect:/pages/final.html";
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
Insert title here
final.html
Insert title here
A simple HTML page
HelloWeb-servlet.xml
web.xml
Spring MVC Application
HelloWeb
org.springframework.web.servlet.DispatcherServlet
1
HelloWeb
/
index.jsp 跳过去 报404了?怎么回事 .不知道html后缀吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把index.jsp 放入/WEB-INF/jsp/目录下。
以上是spring-mvc.xml
思路就是把html放成静态资源文件,然后在返回就行了
我的调用:

不配置尾缀也可以,但是设置成静态资源文件很重要:
有为题追问我~
为什么要走controller里面走呢。。。( •̅_•̅ ) 直接页面跳转HTML不好吗
你需要这个http://www.thymeleaf.org