简体   繁体   English

当我在openshift上部署它时,在WEB应用程序中的搜索仅适用于拉丁符号,但在本机上可以正常使用

[英]Search in my WEB-application works only with latin symbols when I deploy it on openshift, but it works fine on my local machine

I have a problem. 我有个问题。 I made a WAB-application by Spring MVC & Hibernate and it has a search. 我通过Spring MVC和Hibernate制作了WAB应用程序,并且进行了搜索。 Problem is the search works only with latin symbols when I deploy the WEB-application on openshift. 问题是,当我在openshift上部署WEB应用程序时,搜索仅适用于拉丁文符号。 It doesn't work with cyrillic. 西里尔字母不适。 But it works very well on my local machine. 但是它在我的本地计算机上运行得很好。 So I have no idea what it can be. 所以我不知道这可能是什么。 I have the same database on openshift that on my local machine and I did a dump of my data and imported it to openshift. 我在openshift上有与本地计算机上相同的数据库,我转储了数据并将其导入到openshift中。

This is the method of search: 这是搜索方法:

public List<News> getNewsWithSubstring(String str) {
    Session session = sessionFactory.getCurrentSession();
    Criteria crt = session.createCriteria(News.class);
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.like("titleUa", "%" + str + "%"));
    disjunction.add(Restrictions.like("titleEn", "%" + str + "%"));
    disjunction.add(Restrictions.like("titleRu", "%" + str + "%"));
    disjunction.add(Restrictions.like("descriptionUa", "%" + str + "%"));
    disjunction.add(Restrictions.like("descriptionEn", "%" + str + "%"));
    disjunction.add(Restrictions.like("descriptionRu", "%" + str + "%"));
    crt.add(disjunction);
    return crt.list();
}

This is the settings of connect to db (from springServlet-context.xml): 这是连接到数据库的设置(来自springServlet-context.xml):

 <bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="com.goldcamtech.model"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="c3p0.idle_test_period">120</prop>
            <prop key="hibernate.connection.characterEncoding">utf8</prop>
        </props>
    </property>
</bean>

<bean name="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://127.18.97.4:3306/gctech_site?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="username" value="username"/>
    <property name="password" value="password"/>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

Maybe someone has any idea? 也许有人有什么主意? Why does it work with latin and cyrillic on my local machine but doesn't work with cyrillic on openshift? 为什么在我的本地计算机上不能使用拉丁文和西里尔文,但在openshift上不能与西里尔文一起使用? Thanks! 谢谢!

Most likely the problem lies in default configuration of MySQL on your local machine and MySQL at OpenShift. 问题很可能出在本地计算机上的MySQL的默认配置以及OpenShift上的MySQL的默认配置。 I suggest to compare the CHARACTER SET on the tables/database. 我建议比较表/数据库上的CHARACTER SET If you didn't specify it explicitly when creating tables/database MySQL will use default value from my.cnf 如果在创建表/数据库时未明确指定,则MySQL将使用my.cnf默认值

See also: Database Character Set and Collation 另请参阅: 数据库字符集和排序规则

PS Also be warned, that code like this PS也请注意,这样的代码

disjunction.add(Restrictions.like("titleUa", "%" + str + "%"));

may work wrong in some situations (for instance, if user's string contains % or _ characters) and even more, it may cause SQL injection. 在某些情况下(例如,如果用户的字符串包含%_字符)可能会出错,甚至更多,这可能会导致SQL注入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 mvn clean deploy 从同一台机器将工件上传到 Nexus,在我的本地 Windows 10 机器上工作正常 - Not able to upload artifacts to Nexus from the same machine using mvn clean deploy, works fine from my local Windows 10 machine 将.war文件部署到tomcat 8在IDE中工作正常,但是当我部署到我的VPS时,我丢失了所有的JS和CSS - Deploying .war file to tomcat 8 works fine in IDE but I lose all my JS and CSS when I deploy to my VPS 在JBoss AS 7上部署Web应用程序时出错 - Error when deploy web-application on JBoss AS 7 无法通过 jenkins 上的 chrome webdriver 启动 chrome,因为它在我的本地机器上运行良好 - Unable to launch chrome via chrome webdriver on jenkins where as it works fine on my local machine 通过设备运行USB调试时,UI会失真,但在AVD上可以正常工作 - My UI gets distorted when I run it through my device(USB debugging) but works fine on my AVD Restlet代码在本地有效,但在部署时无效(在Openshift上) - Restlet code works on local but not when deployed (on Openshift) 如何将我的 JavaScript 网络应用程序转换为 android 应用程序? - How can I convert my JavaScript web-application into android application? Java Spring MVC WebSocket应用程序只能在本地应用程序服务器上运行,而不能在openshift主机上运行 - Java Spring MVC WebSocket application works on local application server only but not on openshift host 我的程序只能在 NetBeans 中运行,但是当我将它构建到 JAR 中时它就无法运行 - My program only works in NetBeans, but when i build it into JAR it is not working 如何将XSD模式与Web应用程序一起使用 - How to use xsd schema with path withing my web-application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM