我正在使用AngularJs构建Web应用程序,尝试为我的应用程序使用angular-translate。 这是Doc: http://www.ng-newsletter.com/posts/angular-translate.html
$translateProvider.useStaticFilesLoader({
prefix: 'assets/resources/',
suffix: '.json'
});
我的项目目录中有2个json文件
webapp/assets/resources/locale-en_US.json
webapp/assets/resources/locale-ru_RU.json
当我在浏览器中运行我的应用时,我收到此错误
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/assets/resources/locale-ru_RU.json
我尝试从位于我的json文件的同一目录中加载 .js 文件以及 .jpg
webapp/assets/resources/foo.jpg
一切正常,我无法从本地加载 JSON 文件。我试图提出$ http请求,但没有结果。
$http.get('assets/resources/locale-en_US.json' ).success(function(data) {
console.log(data);
});
看起来我的项目忽略了本地的json文件。我进行了研究并提出了一些建议,以便将映射添加到 web.xml 。没有结果
<mime-mapping>
<extension>json</extension>
<mime-type>application/json</mime-type>
</mime-mapping>
任何想法该怎么做?
此致 Gari.E
答案 0 :(得分:0)
我的 web.xml
中有 servlet-mapping<servlet-mapping>
<servlet-name>shemoGeServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
正在 WEB-INF 目录中搜索 jsno 文件,但我的 jsno 文件位于资产目录中。这是我的 servlet-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:annotation-driven/>
<mvc:resources location="/assets" mapping="/assets/**"/>
<context:component-scan base-package="ge.shemo"/>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
<property name="defaultViews">
<list>
<!-- JSON View -->
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true" />
</bean>
</constructor-arg>
</bean>
</list>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages"></bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/>
</beans>
这就是我得到的原因
Failed to load resource: the server responded with a status of 404 (Not Found)
我删除了servlet并且问题消失了
<servlet-mapping>
<servlet-name>shemoGeServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>