火狐提示 纯文本文件的字符编码未声明。如果该文件包含 US-ASCII 范围之外的字符,该文件将在某些浏览器配置中呈现为乱码。该文件的字符编码需要在传输协议层

mantouqizuo 2017-07-09 06:02:23
我配置的简单的ssm框架:
application.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">


<!-- 导入properties文件 -->
<context:property-placeholder location="classpath:properties/base.properties"/>

<!-- 这个标签注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例,
controller使用的一些前提,如果不添加的话,可能某些功能缺失:启动注解驱动 -->
<mvc:annotation-driven></mvc:annotation-driven>

<!-- 数据源缓冲池配置 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.name}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
</bean>

<!-- 扫描包中被标记类,来注入到容器中 -->
<context:component-scan base-package="com.org.fl">
<!-- 五种不同种类的扫描类型,可以随时扫描 -->
</context:component-scan>

<!-- 会自动将扫描到的dao和sqlsessionfactorybean中的mapping.xml结合起来,自动映射两者的关系,所以这里要配置dao路径 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sessionFactoryBean"></property>
<property name="basePackage" value="com.org.fl.dao"/>
</bean>

<!--session工厂 -->
<bean id="sessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>

<!-- 别名<property name="typeAliasesPackage" value="com.org.fl.vo"></property> -->

<!-- mybatis文件配置引用<property name="configLocation" value="classpath:/mybatis-config.xml"></property> -->

<!-- 会自动扫描该路径下的所有文件并解析 -->
<property name="mapperLocations" value="classpath:/mappings/*.xml"/>

<!-- 拦截器 -->
<!-- <property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=hsqldb
reasonable=true
</value>
</property>
</bean>
<bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=com.github.abel533.mapper.Mapper
IDENTITY=MYSQL
notEmpty=true
</value>
</property>
</bean>
</array>
</property> -->
</bean>

<!-- 开启事物 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 指定事物管理器名字:transaction-manager(就是上面那个) -->
<tx:annotation-driven/>

</beans>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<!-- 资源是放在resources中,classpath找不到,这时候需要全局先声明一下 -->
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:peizhi/applicationContext.xml</param-value>
</context-param>

<!-- 字符集 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<!-- 是否会覆盖request.getEncoding中的设置 -->
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<!-- spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 扩展spring bean的作用域有request,session,global session等使Spring支持request与session的scope, 如:<bean id="loginAction" class="com.foo.LoginAction" scope="request"/> -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- 核心控制器 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:peizhi/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<!-- session失效 -->
<session-config>
<session-timeout>120</session-timeout>
</session-config>

<!-- 错误页面 -->
<error-page>
<error-code>400</error-code>
<location>/WEB-INF/view/commons/error/400.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/view/commons/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/view/commons/error/500.jsp</location>
</error-page>


</web-app>

controller方法
@RequestMapping("/userList")
@ResponseBody
public List<User> userList( ){
List<User> list=userService.queryUser();
return list;
}

@RequestMapping("/userListView")
public String userListView( ){
return "index.jsp";
}


错误的地方是在下面这个方法,上面的json可以正常显示,下面这个就不行了,无论return的字符串中的页面是否存在,火狐控制台都报错“纯文本文件的字符编码未声明。如果该文件包含 US-ASCII 范围之外的字符,该文件将在某些浏览器配置中呈现为乱码。该文件的字符编码需要在传输协议层声明,或者在文件中加入一个 BOM(字节顺序标记)。”


网上说是页面头的问题,我在页面加了没用,我感觉应该是我配置或者设置的问题,因为我return "index.jsp"; 改成 return "1";不存在的页面它都报这个错误。

只有在火狐的控制台才有这个错误,并且显示空白页面,其他地方显示404

跪求大神指教!!!!!
...全文
7865 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ApMa 2018-03-12
  • 打赏
  • 举报
回复
第一次见你这样的,解决问题不说清楚的
hlmx66880429 2018-01-20
  • 打赏
  • 举报
回复
是啊,说一下怎么解决的啊
小流至江河 2017-12-25
  • 打赏
  • 举报
回复
对啊,楼主自己解决完,怎么自己不说清楚
LegendOfBush 2017-07-27
  • 打赏
  • 举报
回复
楼主你好,遇到同样的问题,能否具体说一下是哪里配置的问题?
mantouqizuo 2017-07-10
  • 打赏
  • 举报
回复
引用 5 楼 hanpoyangtitan 的回复:
@RequestMapping(value="/。。。。。。。", method=RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
跟这个没关系,已经解决了,是配置的小问题,坑爹的问题调试了半天才发现,在web.xml中哦
什么都不能 2017-07-10
  • 打赏
  • 举报
回复
@RequestMapping(value="/。。。。。。。", method=RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
mantouqizuo 2017-07-09
  • 打赏
  • 举报
回复
引用 3 楼 pany1209 的回复:
没遇到过。。springmvc的配置文件看看。。。。
mvc这边我没有细配,我只是搭建一个简单的ssm框架,什么视图解析器,拦截器等我都没有配置,关键这应该不影响我简单功能实现吧,对了,这个项目是maven项目,是不是我的pom.xml中问题?
李德胜1995 2017-07-09
  • 打赏
  • 举报
回复
没遇到过。。springmvc的配置文件看看。。。。
mantouqizuo 2017-07-09
  • 打赏
  • 举报
回复
mantouqizuo 2017-07-09
  • 打赏
  • 举报
回复
有没有人啊,是不是要给分啊,在什么地方给啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧