有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java OpenShift返回响应,标题为text/plain,而不是text/html

首先,我的英语不好(我是越南人),很抱歉

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

problem

以下是我的应用程序结构:

structure

以及我的资源映射配置:

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

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

MIME Type Mappings: When serving static resources, Tomcat will automatically generate a "Content-Type" header based on the resource's filename extension, based on these mappings in web.xml file.

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

<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>

但并不是所有人都成功了

更新:添加网页。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>

有人能帮我解决这个问题吗

提前感谢您的帮助


共 (1) 个答案

  1. # 1 楼答案

    正如我所看到的,这个urlhttps://bms-sps2.rhcloud.com/bms/index.html#/按预期工作(显示为html),但根上下文路径不工作。我的建议是在你的网站上添加欢迎文件列表。xml,以便tomcat可以将页面用作html

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