我用JSP做了一个注册页面~要求你填写:姓名,密码~~
但提交后我查看数据库(sqlserver2005)发现表里面是乱码!(只有数字能正常的显示)
请教各位是什么原因?难道是我数据库表里面的类型设置错了?(我数据库里设置的类型是Vchar(50))

解决方案 »

  1.   

    页面设置编码类型utf-8。response设置编码类型utf-8,试试
      

  2.   

    我晕,插入的都是乱码了,查出来当然也是乱码拉
    添加一个中文过滤器就OK了
    MyFilter.java文件内容:
    package cn.common.filter;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;/**
     * 设置中文编码格式
     * @author zhangyang
     *
     */
    public class MyFilter extends HttpServlet implements Filter {
        private FilterConfig filterConfig;
        //Handle the passed-in FilterConfig
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
        }    //Process the request/response pair
        public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain filterChain) {
            try {
             request.setCharacterEncoding("GBK");
                filterChain.doFilter(request, response);
            } catch (ServletException sx) {
                filterConfig.getServletContext().log(sx.getMessage());
            } catch (IOException iox) {
                filterConfig.getServletContext().log(iox.getMessage());
            }
        }    //Clean up resources
        public void destroy() {
        }
    }然后在配置文件中添加就行了
    web.xml中配置
               <filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>
    cn.common.filter.MyFilter
    </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>gbk</param-value>
    </init-param>
    </filter>应该没问题了,如果还不行,再问我!
      

  3.   

    首先谢谢各位朋友:楼上的我按你的方法做了,但是:你告诉我的XML文件:web.xml中配置 
    <filter> 
    <filter-name>MyFilter </filter-name> 
    <filter-class> 
    cn.common.filter.MyFilter 
    </filter-class> 
    <init-param> 
    <param-name>encoding </param-name> 
    <param-value>gbk </param-value> 
    </init-param> 
    </filter> 
    放在web.xml里的什么地方?我放了怎么是有错:The up in the document following the root element must be well-formed
      

  4.   

    是你的页面设置的编码格式问题,jsp上面的编码格式!action里转换一下
      

  5.   

    放到<web-app>下边就行 ,放到servlet上边  你是通过servlet后在入库的吧 ?
      

  6.   

    数据库里面字段类型为varchar的全部改成nvarchar就ok了
      

  7.   

    new String(request.getParameter("").getBytes("ISO-8859-1"),"utf-8");
    把你request.getParameter的值用这句转换一下
      

  8.   

    如果是GET方式获取,在TOMCAT下还要改server.xml的东西,网上中文乱码的文章很多啊!
    我用MySQL中还正常了。