插入进去是好的,用数据库select也正常 查询页面时如果查询的是中文名字则会出现乱码(乱码直接出现在text中),如果查询的名字是英文,则显示正常(显示正常的意思是其他中文的信息也会显示出来),最 后发现只要在查询框(text)不输入中文,则不会显示乱码,可能问题就出在这了,但搞了很久都没搞定,有点失去信心了请大家帮帮忙吧! 说明一下,简单的实现的是按人名查询人的信息!

解决方案 »

  1.   

    用一下filter吧jsp版AJAX下拉条级联 这个项目里有关于filter的使用、配置
      

  2.   

    插进去是好的,响应出来是乱码可能是 contentType="text/html;charset=GBK"  or response.setCharacterEncoding("GBK")
      

  3.   

    我用的是oracle,是一致的,因为插进去是正确的!
      

  4.   

    你用的hibernate ?我用hibernate也出现过这种情况~~~如果是hibernate我还可以帮你看看~~
      

  5.   

    改成这样看看行不~
    <%@ page language="java" import="java.util.*" pageEncoding="gb2312" contentType="text/html; charset=gb2312"%>
      

  6.   

    用Hibernate的话,在Web.xml下加一个filter过滤器
    用Serverlet的话,在Serverlet的doPost或者doGet方法中加
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    当然,你Jsp页面的pageEncoding="UTF-8"
      

  7.   

    是的struts+hibernate+spring整合的ps:我也喜欢一护,哈哈
      

  8.   

    你用的应该是hibernate3,或更低的版本
    在hibernate.cfg.xml中的<session-factory>的配置中加一行<property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    或者换3.0以上版本~~试试吧
      

  9.   

    我是spring中配置sessionfactory的,加上后提示这个类没找到的错误
      

  10.   

    action:import beans.*;
    import util.*;
    /** 
     * MyEclipse Struts
     * Creation date: 10-08-2007
     * 
     * XDoclet definition:
     * @struts.action path="/researcher" name="researcherForm" input="/researcher_insert.jsp" scope="request"
     */
    public class ResearcherAction extends BaseAction {

     private static final String CONTENT_TYPE = "text/html; charset=GB2312";


    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) throws Exception {


    ResearcherForm researcherForm = (ResearcherForm) form;

             request.setCharacterEncoding("gb2312");

    HttpSession session = request.getSession();

    String  = new String();

            String name = researcherForm.getName();
            if(name!=null ) name = new String(name.getBytes("iso8859_1"), "gb2312");
            if (name == null) {
                name = "";
            }
            String sex = researcherForm.getSex();
            if(sex!=null ) sex = new String(sex.getBytes("iso8859_1"), "gb2312");
            if (sex == null) {
                sex = "";
            }
            String title = researcherForm.getTitle();
            if(title!=null ) title = new String(title.getBytes("iso8859_1"), "gb2312");
            if (title == null) {
                title = "";
            }
            
            
            String career = researcherForm.getCareer();
            if(career!=null ) career = new String(career.getBytes("iso8859_1"), "gb2312");
            if (career == null) {
                career = "";
            }
            
           
            int rid = Integer.parseInt(researcherForm.getRid());
         
            
           String[] check = researcherForm.getCheck();        response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();        String command = researcherForm.getCommand();
       if(command!=null) {
       command = command.trim();
           command = new String(command.getBytes("iso8859_1"), "gb2312");
       }
       
       System.out.println("要执行的操作是:" + command);    boolean bool = false;     
          Researcher researcher = new Researcher();
        
              researcher.setRid(rid);
              researcher.setName(name);
              researcher.setSex(sex);
              researcher.setTitle(title);
              researcher.setCareer(career);
           
           
           IResearcherDAO researcherDAO = getResearcherService().getResearcherDAO();
           
           String condition = new String();
           PageBean pageBean = new PageBean();       //添加信息  if (command.equals("insert")) {      bool = researcherDAO.saveResearcher(researcher);      if (bool) {
              out.println("<script language=javascript>alert('添加成功!')");
              out.println("location.href='researcher/query.jsp'</script>");
              out.close();      } else {
              out.println("<script language=javascript>alert('错误!添加未成功!')");
              out.println("location.href='researcher/query.jsp'</script>");
              out.close();      }
      }   //查询
      if (command.equals("query")) {
      
      System.out.println("Here is ResearcherAction");   condition = researcherForm.getCondition();
      //if(condition!=null) condition = new String(condition.getBytes("iso8859_1"),"gb2312");
      System.out.println("The query condition is: "+condition);
      if(condition==null) condition="";
      
      session.setAttribute("condition", condition);
     
      
      int pageNum = 5;
        int currPage=0;
       
          pageBean.setPageNum(pageNum);
          pageBean.setCurrPage(currPage);
          pageBean.setCondition(condition);        ArrayList ls = (ArrayList)researcherDAO.getResearcher(pageBean);        session.setAttribute("queryResult", ls);
            
             = "queryPage";      }
      
      
         //更新信息  if (command.equals("update")) {       bool = researcherDAO.updateResearcher(researcher);      if (bool) {
                  out.println("<script language=javascript>alert('修改成功!')");
                     //out.println("window.close()</script>");
                    out.println("location.href='researcher/query.jsp'</script>");
                      out.close();              } else {
                          out.println("<script language=javascript>alert('错误!修改未成功!')");
                              //out.println("window.close()</script>");
                              out.println("location.href='researcher/query.jsp'</script>");
                              out.close();              }
      }
        
    //删除信息  if (command.equals("删除")) {
          if (check != null) {
              int num = check.length;
              for (int i = 0; i <= num - 1; i++) {
                  System.out.println("check[i]=" + check[i]);
                 bool = researcherDAO.delResearcher(check[i]);
                  if (bool) {
                      out.println("<script language=javascript>alert('删除成功!')");
                      out.println("location.href='researcher/query.jsp'</script>");
                      out.close();
                  }
                  else {
                      out.println("<script language=javascript>alert('删除未成功!')");
                      out.println("location.href='researcher/query.jsp'</script>");
                      out.close();
                  }          }
          }
      }

    return mapping.findForward();
    }


    }
      

  11.   

    查询页面:<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ page contentType="text/html; charset=GB2312" %>
    <%@ page import="java.util.*, beans.*, dao.*, util.*" %>
    <%request.setCharacterEncoding("gb2312");
    response.setCharacterEncoding("gb2312");
     %>
    <html:html>
    <LINK href="../css/style.css" rel=stylesheet type=text/css>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>
      研究人员浏览与查询
    </title>
    </head>
    <body bgcolor="#ffffff">
     <br>
    <br>
    <br>
    <h1 align="center">研究人员浏览与查询 </h1>
    <br><html:form action="researcher"  method="post" enctype="gb2312">
    <html:hidden value="query" property="command"/>
          <div align="right">
            研究人员搜索  <html:text property="condition" />
              &nbsp;&nbsp;&nbsp;
              <html:submit value="查询" property="submit"/> &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;
          &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;   &nbsp;&nbsp;&nbsp;
          </div>
      </html:form>  <br><br>
      
      
    <html:form action="researcher"  method="post" >
    <table width=70% border=0 cellpadding="3" cellspacing="1" align="center">
       <tr bgcolor=#8899cc>
         <td>  </td>
        <td> 编号 </td>
       <td> 姓名 </td>
       <td>性别</td>
       <td>职称</td>
        <td> 简介 </td>
       </tr><%
      request.setCharacterEncoding("gb2312");
      PageBean pageBean = new PageBean();  //String condition = request.getParameter("condition");
       String condition = (String)session.getAttribute("condition");
       session.removeAttribute("condition");
      if(condition!=null) condition = new String(condition.getBytes("iso8859_1"),"gb2312");
      System.out.println("The query condition is: "+condition);
      if(condition==null) condition="";  int pageNum = 5;
      int currPage;
      String url = "researcher/query.jsp"; 
       if (request.getParameter("pages")==null) {
         currPage =0;
       }
       else {
            currPage = new Integer(request.getParameter("pages")).intValue();
       }   System.out.println("Here is currPage!");    pageBean.setPageNum(pageNum);
        pageBean.setCurrPage(currPage);
        pageBean.setCondition(condition);
        
        session.setAttribute("pageBean",pageBean);
        
        
        ArrayList list = (ArrayList)session.getAttribute("queryResult");
       // session.removeAttribute("queryResult");
        
          int start = currPage * pageNum;  //当前页的开始记录
            int  end = start + pageNum;  //当前页的结束记录
           
         
           if(list!=null && list.size()!=0) {
           
           for(int i=start;i<end; i++ ) {
    if(i<list.size()) {
    Researcher info = (Researcher)list.get(i);

        session.setAttribute(String.valueOf(info.getRid()),info);
    %>
    <tr bgcolor=#ffffff>
      <td> <html:checkbox property="check" value="<%=String.valueOf(info.getRid())%>" /> </td>
    <td><%=info.getRid()%> </td>
    <td> <%=info.getName()%></td>
    <td><%=info.getSex()%></td>
    <td><%=info.getTitle()%></td>
    <td><%=info.getCareer()%></td><td> <a href="researcher/update.jsp?rid=<%=String.valueOf(info.getRid())%>" target="_self">修改 </a> </td>
    </tr>
    <%  } }}%><tr>
    <td> </td>
    <td> </td>
    <td> </td><td> </td>
    </tr></table>
    <p align=center>
    <%=Pagination.getPaginationScript(pageBean.getCurrPage(),pageBean.getPageNum(),PageBean.getRecordNum(),pageBean.getCondition(),url)%>
    </p>
    <br><br>
    <p align=center>  <html:submit value="删除" property="command"/>
    </p>
    <div >&nbsp;&nbsp;&nbsp;&nbsp;</div>
    </html:form>
    </body>
    </html:html>
      

  12.   

    myeclipse
    自带的spring-hibernate3.jar
      

  13.   

    贴你查询数据库的那段代码,有hql语言的那段
      

  14.   

    是struts+hibernate+spring整合的,是又struts做控制层的,hibernate只是作为一个持久层,所以具体执行操作的是action,貌似不用hql
      

  15.   

    你这种情况肯定是hibernate的问题~~~你把hql语句在控制台显示出来看看~~~查询条件如果是中文肯定是乱码,而在进hql语言之前这个查询条件肯定不是乱码,我觉得还是换包比较好,这应该是hibernate自己封装的问题,或者你用sql语句算了~~用session.createSQLQuery(sql)来得到查询结果