【问题标题】:Deployment server uses "application/x-octet-stream"部署服务器使用“application/x-octet-stream”
【发布时间】:2013-08-22 09:32:11
【问题描述】:

在将 Spring-MVC 应用程序部署到 Tomcat 服务器时,我遇到了一个问题:服务器一直使用 application/x-octet-stream 作为响应类型。因此,浏览器不会显示该页面,而是提供下载。

该网站在本地 Tomcat 服务器上按预期运行 - 也许该服务器具有不同的默认设置?

该 URL 类似于以下 URL:http://www.example.org/mysite/search

我的 web.xml(部分):

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

还有servlet-context.xml:

<beans:bean id="viewResolver"
    class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
    <beans:property name="cache" value="true" />
    <beans:property name="prefix" value="" />
    <beans:property name="suffix" value=".vm" />
</beans:bean>
<beans:bean id="velocityConfig"
    class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
    <beans:property name="resourceLoaderPath" value="/WEB-INF/views/" />
</beans:bean>
<context:component-scan base-package="org.example.website" />

如何在我的项目中将默认 MIME 类型更改为 text/html,以便它可以在所有服务器上运行而无需额外配置?

【问题讨论】:

    标签: java tomcat spring-mvc mime-types velocity


    【解决方案1】:

    在配置viewResolver bean 时尝试调用VelocityLayoutViewResolver.setContentType

        <beans:property name="contentType" value="text/html" />
    

    【讨论】:

    • 奇怪 - 在我的本地开发服务器上,此属性允许我更改类型。但是,部署服务器似乎忽略了此属性,并继续将页面作为“application/x-octet-stream”提供...
    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 2019-01-21
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    相关资源
    最近更新 更多