javascript - SpringMVC怎么支持html视图啊?

 来杯冰柠檬水 发布于 2022-11-09 19:31

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


http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   

   
      
      
   

web.xml


http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

   Spring MVC Application

   
      HelloWeb
      
         org.springframework.web.servlet.DispatcherServlet
      
      1
   

   
      HelloWeb
      /
   

index.jsp 跳过去 报404了?怎么回事 .不知道html后缀吗?

4 个回答
  • 2022-11-12 11:02 回答
  • 为什么要走controller里面走呢。。。( •̅_•̅ ) 直接页面跳转HTML不好吗

    2022-11-12 11:02 回答
  • 以上是spring-mvc.xml
    思路就是把html放成静态资源文件,然后在返回就行了

    我的调用:

    不配置尾缀也可以,但是设置成静态资源文件很重要:

        <mvc:resources mapping="/WEB-INF/web/**" location="/WEB-INF/web/"/>

    有为题追问我~

    2022-11-12 11:02 回答
  • 把index.jsp 放入/WEB-INF/jsp/目录下。

    2022-11-12 11:02 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有