本文介绍了Primefaces阿贾克斯字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,更新与AP值:P中commandbutton.when:的commandButton,我设置的ajax =真所有的事情是好的,但是当我设置的ajax =假,值的号码:inputText的没有编码,并在接下来的页面显示我UO±UU。发送到mysql数据库或当。我使用的过滤器,但我的问题没有解决。

请帮我谢谢

 < XML版本=1.0编码=UTF-8&GT?;
!< D​​OCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
      的xmlns:H =htt​​p://xmlns.jcp.org/jsf/html
      的xmlns:P =htt​​p://primefaces.org/ui>
    < META HTTP-当量=内容类型内容=text / html的;字符集= UTF-8/>
    < H:头>
        <冠军>的facelet标题< /标题>
    < / H:头>
    < H:身体GT;
        < H:形式GT;
            <电话号码:inputText的值=#{bean.name}/>
            <电话号码:的commandButton值=检查阿贾克斯=假行动=第2页/>
        < /小时:形式GT;
    < / H:身体GT;
< / HTML>
 

解决方案

我应该使用过滤器的解决这个问题。

 <滤光器>
    <过滤器名称>&EncodingFilter LT; /过滤器名称>
    <过滤器类和GT; myengineer.EncodingFilter< /过滤器级>
< /滤光器>
<过滤器映射>
    <过滤器名称>&EncodingFilter LT; /过滤器名称>
    < URL模式> / *< / URL模式>
< /过滤器映射>
 

和java类过滤器

 包myengineer;

进口java.io.IOException异常;

进口javax.servlet.Filter的;
进口javax.servlet.FilterChain;
进口javax.servlet.FilterConfig;
进口javax.servlet.ServletException;
进口javax.servlet.ServletRequest;
进口javax.servlet.ServletResponse;

/ **
 *
 * @author阿尔法
 * /
公共类EncodingFilter实现过滤器{
                   /// =============================================== ====================================
公共无效的init(一个FilterConfig配置)抛出了ServletException {
    //空操作
}
    /// =============================================== ====================================
    公共无效的doFilter(ServletRequest中要求,ServletResponse的响应的FilterChain链)
                                                       抛出IOException异常,ServletException异常{
        request.setCharacterEncoding(UTF-8);
        response.setCharacterEncoding(UTF-8);
        chain.doFilter(请求,响应);
    }
    /// =============================================== ===================================
    公共无效的destroy(){
        //空操作
    }
    /// =============================================== ====================================
}
 

I have a problem updating values with a p:commandbutton.when in p:commandButton , I am set ajax="true" all thing is Ok , but when I am set ajax="false" , value in the p:inputText do not encoding and in the next page show me ÙرÛÙ . or when send to mysql database .I am using Filter but my problem does not solve.

please Help meThanks

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form>
            <p:inputText value="#{bean.name}" />
            <p:commandButton value="check" ajax="false" action="page2"/>
        </h:form>
    </h:body>
</html>
解决方案

I should use Filter for solve this problem.

    <filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>myengineer.EncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

and java class filter

package myengineer;

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;

/**
 *
 * @author alfa
 */
public class EncodingFilter implements Filter{
                   ///===================================================================================
public void init(FilterConfig config) throws ServletException {
    //No-op
}
    ///===================================================================================
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain       chain) 
                                                       throws IOException,     ServletException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        chain.doFilter(request, response);
    }
    ///==================================================================================
    public void destroy() {
        //No-op
    }    
    ///===================================================================================
}

这篇关于Primefaces阿贾克斯字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 12:49