Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从maven项目返回网页_Java_Maven_Jsp - Fatal编程技术网

Java 如何从maven项目返回网页

Java 如何从maven项目返回网页,java,maven,jsp,Java,Maven,Jsp,我正在尝试使用maven项目返回网页。这适用于html页面,但我需要JSP。当我尝试在控制台上加载JSP页面时,表示dispatcherservlet的初始化已开始,但该网页未返回到浏览器 代码如下: 主要类别: package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; i

我正在尝试使用maven项目返回网页。这适用于html页面,但我需要JSP。当我尝试在控制台上加载JSP页面时,表示dispatcherservlet的初始化已开始,但该网页未返回到浏览器

代码如下:

主要类别:

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@SpringBootApplication
@Configuration
@ComponentScan(basePackages="com.example")
@EnableWebMvc
public class DemoApplication extends WebMvcConfigurerAdapter{

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("static/templates/");
        resolver.setSuffix(".jsp");
        return resolver
   }



    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
和我的控制器类:

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {

     @RequestMapping(value="/home")
        public String home(){
            return "home";
        }

}

如果你能提供你得到的回应,那就太好了。 您可以尝试将
@ResponseBody
添加到控制器

@Controller
public class HomeController {
     @RequestMapping(value="/home")
     @ResponseBody
        public String home(){
            return "home";
        }
}

如果你能提供你得到的回应,那就太好了。 您可以尝试将
@ResponseBody
添加到控制器

@Controller
public class HomeController {
     @RequestMapping(value="/home")
     @ResponseBody
        public String home(){
            return "home";
        }
}