gpt4 book ai didi

java - OpenShift 返回带有标题 text/plain 而不是 text/html 的响应

转载 作者:行者123 更新时间:2023-11-28 22:02:00 25 4
gpt4 key购买 nike

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

我是 OpenShift 新手。我在 OpenShift 上托管了我的 Java Web 应用程序(Spring MVC Restful + AngularJS)https://bms-sps2.rhcloud.com/bms .当我访问它时,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>

但都没有成功。

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

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

在此先感谢您的帮助。

最佳答案

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

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

关于java - OpenShift 返回带有标题 text/plain 而不是 text/html 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34105234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com