Spring mvc SpringMVC最新版本,html响应正在下载而不是显示

Spring mvc SpringMVC最新版本,html响应正在下载而不是显示,spring-mvc,servlet-3.0,wildfly-8,Spring Mvc,Servlet 3.0,Wildfly 8,我有一个非常简单的spring mvc web应用程序,运行在wildfly 8.2.0服务器上。使用spring注释配置完全配置,包括WebApplicationInitializer(无web.xml)。控制器被调用,但我的结果页被下载而不是显示。下面是我的配置和控制器代码 配置代码 @Configuration @EnableWebMvc @ComponentScan(basePackages = { "com.sample.web.controllers" }) public clas

我有一个非常简单的spring mvc web应用程序,运行在wildfly 8.2.0服务器上。使用spring注释配置完全配置,包括WebApplicationInitializer(无web.xml)。控制器被调用,但我的结果页被下载而不是显示。下面是我的配置和控制器代码 配置代码

@Configuration 
@EnableWebMvc
@ComponentScan(basePackages = { "com.sample.web.controllers" })
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver bean = new InternalResourceViewResolver();
        bean.setPrefix("/WEB-INF/views/");
        bean.setSuffix(".jsp");
        return bean;
    }

    @Bean(name = "multipartResolver")
    public CommonsMultipartResolver getMultipartResolver() {
        return new CommonsMultipartResolver();
    }
}
控制器代码为

@Controller
public class HomeController {

    @RequestMapping(value="/hello",method=RequestMethod.GET)
    public String sayHello(){
        return "hello";
    }
}
我的hello.jsp在WEB-INF/views/hello.jsp中

有什么想法吗?为什么结果html被下载而不是显示在浏览器中? 它作为application/octet流下载,没有任何文件扩展名,文件内容是我的jsp的html

4:59:11812调试[org.springframework.web.servlet.DispatcherServlet](默认任务-2)名为“dispatcher”的DispatcherServlet处理[/sample/common/hello]的GET请求 14:59:11816调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](默认任务2)查找path/common/hello的处理程序方法 14:59:11822调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](默认任务-2)返回处理程序方法[public java.lang.String org.egov.admin.web.controllers.common.HomeController.sayHello()] 14:59:11822调试[org.springframework.beans.factory.support.DefaultListableBeanFactory](默认任务-2)返回单例bean“homeController”的缓存实例 14:59:11824调试[org.springframework.web.servlet.DispatcherServlet](默认任务-2)[/sample/common/hello]最后修改的值是:-1 HomeController的sayHello方法中的14:59:24750信息[org.egov.admin.web.controllers.common.HomeController](默认任务-2) 14:59:24762调试[org.springframework.beans.factory.support.DefaultListableBeanFactory](默认任务-2)调用名为“common/hello”的bean上的AfterPropertieSet() 14:59:24762调试[org.springframework.web.servlet.DispatcherServlet](默认任务2)在DispatcherServlet中呈现视图[org.springframework.web.servlet.view.JstlView:name'common/hello';URL[/web-INF/views/common/hello.jsp]],名称为“dispatcher” 14:59:24766调试[org.springframework.web.servlet.view.JstlView](默认任务2)转发到InternalResourceView“common/hello”中的资源[/web-INF/views/common/hello.jsp] 14:59:24768调试[org.springframework.web.servlet.DispatcherServlet](默认任务-2)名为“dispatcher”的DispatcherServlet处理对[/sample/web-INF/views/common/hello.jsp]的GET请求 14:59:24773调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](默认任务2)查找路径/web-INF/views/common/hello.jsp的处理程序方法 14:59:24773调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping](默认任务2)未找到[/web-INF/views/common/hello.jsp]的处理程序方法 14:59:24774调试[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping](默认任务2)请求[/web-INF/views/common/hello.jsp]的匹配模式为[/**] 14:59:24775调试[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping](默认任务2)请求[/web-INF/views/common/hello.jsp]的URI模板变量为{} 14:59:24776调试[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping](默认任务2)将[/web-INF/views/common/hello.jsp]映射到HandlerExecutionChain,并使用处理程序[org.springframework.web.servlet.resource]。DefaultServletHttpRequestHandler@4fb5a525]和1个拦截器 14:59:24777调试[org.springframework.web.servlet.DispatcherServlet](默认任务-2)[sample/web-INF/views/common/hello.jsp]最后修改的值是:-1 14:59:24793调试[org.springframework.web.servlet.DispatcherServlet](默认任务-2)返回给名为“dispatcher”的DispatcherServlet的Null ModelAndView:假设HandlerAdapter已完成请求处理 14:59:24793调试[org.springframework.web.servlet.DispatcherServlet](默认任务2)已成功完成请求 14:59:24797调试[org.springframework.web.servlet.DispatcherServlet](默认任务2)已成功完成请求 15:00:00758调试[org.jboss.ejb.client.txn](定期恢复)向节点名为nick laptop的ejb接收方发送事务源节点标识符1的恢复请求

旋度输出

curl -v http://localhost:9090/sample/common/hello
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9090 (#0)
> GET /sample/common/hello HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9090
> Accept: */*
> 
< HTTP/1.1 200 OK
< Connection: keep-alive
< Last-Modified: Thu, 18 Dec 2014 12:29:49 GMT
< X-Powered-By: Undertow/1
* Server WildFly/8 is not blacklisted
< Server: WildFly/8
< Content-Type: application/octet-stream
< Content-Length: 244
< Content-Language: en-IN
< Date: Fri, 19 Dec 2014 09:45:23 GMT
< 
<%@page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title> 
</head>
<body>
Hello There
</body>
* Connection #0 to host localhost left intact
</html>
curl-vhttp://localhost:9090/sample/common/hello
*在DNS缓存中找不到主机名
*正在尝试127.0.0.1。。。
*已连接到本地主机(127.0.0.1)端口9090(#0)
>GET/sample/common/hello HTTP/1.1
>用户代理:curl/7.35.0
>主机:localhost:9090
>接受:*/*
> 
作为更新,如果我不使用WebApplicationInitializer,而是使用具有以下最低内容的web.xml

<context-param>
    <param-name>contextClass</param-name>
    <param-value>
        org.springframework.web.context.support.AnnotationConfigWebApplicationContext
    </param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>org.egov</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
org.springframework.web.context.ContextLoaderListener
SpringDispatcher
org.springframework.web.servlet.DispatcherServlet
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
org.egov
1.
SpringDispatcher
/

如上所述,servlet映射应该在
Servletializer
Java类中设置为
/
,而不是
/*
(如
web.xml
)。

您能展示一个带有curl(HTTP内容和标题)的请求/响应示例,并记录包“org.springframework.web.accept”吗具有调试级别?请