function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
china.leafchina.leaf 

please help me? how can i receive a parameter (encoding gb2312)

system.debug(System.Encodingutil.urlEncode('你好', 'gb2312'));

output  "%C4%E3%BA%C3"

 

system.debug(System.Encodingutil.urlEncode('你好', 'utf-8'));

output  "%E4%BD%A0%E5%A5%BD"

 

 

Page:

<apex:inputTextarea value="{!fchrMsg}" id="fchrMsg"/>

class:

    public string fchrMsg{
        get{
            if(fchrMsg == null){
                string fchrTmpMsg = ApexPages.currentPage().getParameters().get('msg');
                if(fchrTmpMsg != null)
                    fchrMsg = System.Encodingutil.urlDecode(fchrTmpMsg, 'gb2312');
                else
                    fchrMsg = '';
            }
            return fchrMsg;
        }
        set{
            fchrMsg = value;
        }
    }

I want to receive parameter by the url "mypage?msg=%C4%E3%BA%C3"

 

but i get a null value

 

Who can help me!

 

 

Message Edited by china.leaf on 05-12-2009 12:53 AM
Message Edited by china.leaf on 05-12-2009 01:27 AM
yuyinchayuyincha

Apex 好像 没有 System.Encodingutil.urlEncode 这个方法吧。

 

UrlEncode的数据在服务器端接收的时候是不需要Dcode的,会自动Decode的。 

 

另外,在浏览器地址栏中传输的编码基本上都是UTF-8.    

 

所以,你Encdoe的时候不需要加上后面的 utf-8 

yuyinchayuyincha

给你代码你测试一下吧。

 

前端:

<apex:page controller="PageTest"><apex:form> <apex:inputTextarea value="{!msg}"/> </apex:form> <a href="javascript:window.location=window.location+'&msg={!myVar}'">点我吧</a> 

</apex:page>

 

后端:

public class PageTest{ public String msg{ get{ return ApexPages.CurrentPage().getParameters().get('msg'); } set; } public String myVar{ get{ return '你好'; } } 

} 

china.leafchina.leaf

这个肯定是可以的,不用测试了

 

我的情况是在salesforce外面调用的(把page发布成webservice),传进来的时候,msg内容是gb2312编码的.所以接不到参数

yuyinchayuyincha
最好是把你的代码贴出来看一下。(把你的代码简化一下,贴出原型代码)
china.leafchina.leaf

public class PageTest{

    public String msg{

          get{

                   return ApexPages.CurrentPage().getParameters().get('msg');

          }

          set;
    }

 

    public String myVar{

          get{
                  return '%C4%E3%BA%C3';

          }

    }

}

 

改成这样子,获取的msg就是空了,你看一下

 

或者你这样:

 

在page后面加上参数:?msg=%C4%E3%BA%C3

 

你看看获取的msg内容是不是空

 

Message Edited by china.leaf on 05-13-2009 11:50 PM
ChunChun
各位朋友,

我叫Chun Liew.

你们是在中国的吗?

如果是,请和我联系,我的邮箱是c.liew@directhr.net。谢谢,

Chun
yuyinchayuyincha

请注意:浏览器地址栏中不能用gb2312编码过的参数。必须要用utf-8去编码。如:你给出的代码,只要把参数改成utf-8就可以了

 

public class PageTest{

    public String msg{

          get{

                   return ApexPages.CurrentPage().getParameters().get('msg');

          }

          set;
    }

 

    public String myVar{

          get{

        return '%E4%BD%A0%E5%A5%BD';

                  //return '%C4%E3%BA%C3';

          }

    }

}