jsp,servlet,struts等出现乱码的解决办法。
1.首先要保证jsp页面的编码格式、数据库编码格式、java文件保存格式、服务器server.xml中的URIEncoding编码格式保持一致
2 手动写一个过滤器,并且在web.xml文件中进行配置。
具体代码参考如下(调试通过):
package cn.com.model2.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
// TODO Auto-generated method stub
}
}
在web.xml文件中进行配置:
<filter>
<filter-name>CharacterEncoding Set</filter-name>
<filter-class>cn.com.model2.util.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncoding Set</filter-name>
<url-pattern>/*</url-pattern>
</fi
相关文档:
<html>
<head>
<title>marquee</title>
<style>
#marq {
width:500px;
height:100px;
border:1px solid red;
overflow:hidden;
}
#mar ......
下面是jsp代码<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="com.yourcompany.struts.action.Student" %>
<%@ t ......
<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%>< ......
JSP的指令是用来包含外部文件或是进行页面全局设置的;它的有三种,分别是page,include,taglib指令
1.page指令
形如<%@page 属性='值' 属性='值' ........ %>
属性有:
language=''java'' : 设定jsp页面的脚本语言,目前只支持java,默认是java
......