【问题标题】:OpenShift return response with header text/plain instead of text/htmlOpenShift 返回响应,标题为 text/plain 而不是 text/html
【发布时间】:2016-03-10 09:11:41
【问题描述】:

首先,我的英语不好(我是越南人),对此感到抱歉。

我是 OpenShift 的新手。我在 https://bms-sps2.rhcloud.com/bms 的 OpenShift 上托管了我的 Java Web 应用程序(Spring MVC Restful + AngularJS)。当我访问它时,OpenShift 返回纯文本页面而不是 html 页面。但是当我在 localhost 上开发应用程序时,不会出现这个问题。

这是我的应用程序的结构:

还有我的资源映射配置:

<mvc:resources mapping="/" location="/app/index.html/" cache-period="86400" />

在我的研究中,这个问题是因为

MIME 类型映射:提供静态资源时,Tomcat 将根据web.xml 文件中的这些映射,根据资源的文件扩展名自动生成“Content-Type”标头。

如何为没有扩展名的文件添加 mime 映射?我尝试添加 mime-mapping 如下:

<mime-mapping>
    <extension></extension>
    <mime-type>text/html</mime-type>
</mime-mapping>

<mime-mapping>
    <extension>*</extension>
    <mime-type>text/html</mime-type>
</mime-mapping>

<mime-mapping>
    <extension></extension>
    <mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>*</extension>
    <mime-type>text/html</mime-type>
</mime-mapping>

但他们都没有成功。

更新:添加 web.xml

<web-app>
<display-name>Business Management System</display-name>

<servlet>
    <servlet-name>bms</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>bms</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/root-context.xml
    </param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/rest/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
    </filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

有人可以帮我解决这个问题吗?

提前感谢您的帮助。

【问题讨论】:

  • 介绍更多 Openshift 配置。您使用的是哪个服务器?
  • 我在 OpenShift 上的应用是 Tomcat 7 (JBoss EWS 2.0) 和 MySQL 5.5。我正在使用 openshift 的默认配置。
  • 也添加你的 web.xml
  • 抱歉回复晚了,@NikolayRusev。我已经添加了 web.xml

标签: java angularjs spring-mvc tomcat openshift


【解决方案1】:

我可以看到这个 url https://bms-sps2.rhcloud.com/bms/index.html#/ 正在按预期工作(显示为 html ),但根上下文路径不起作用。我的建议是在 web.xml 中添加welcome-file-list,以便tomcat 可以将页面作为html 提供。

<welcome-file-list>  
   <welcome-file>index.html</welcome-file>  
   <welcome-file>index</welcome-file>  
  </welcome-file-list>  

【讨论】:

  • 是的,网址:bms-sps2.rhcloud.com/bms/index.html# 正在按预期工作,但我想当我访问 bms-sps2.rhcloud.com/bms 时它也按预期工作。我添加了欢迎文件列表作为您的建议,但它仍然无法按预期工作。
  • 您还有其他建议吗? @NikolayRusev
  • 如果您有其他建议可以告诉我吗?
  • 我会考虑再告诉你
猜你喜欢
  • 2012-05-19
  • 2012-06-02
  • 2021-08-04
  • 1970-01-01
  • 2013-11-10
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多