URLencoded UTF string returns in wrong encoding from JSP

I have hit behavior that makes me rather unhappy and nothing in docs...
1/ I fetch string in UTF-8, OK
2/ I URLencode it, OK
3/ I click on the link with data from steps 1/,2/, OK
4/ I get the data and siplay it, encoding is wrong
I'm running Tomcat4 and this ehaviour is a bit annoying.
Please, if you know, what I can do with it, tell me, I read the
some docs but found nothing.
Thanks

Encoding is wrong? Use the servlet's getEncoding() method to find out what encoding it used. There is no setEncoding() method until level 2.3 of the servlet specification, and your system is likely not using that. But there may be somewhere in the Tomcat configuration where you can specify the default encoding it should use.

Similar Messages

  • The embedded oc4j in JDeveloper returned a wrong data from the SOAP message

    Greetings,
    I made a webservice in .NET to send simply the current time of the server. then, I developed another client in JDeveloper to receive the time.
    and the object declared in j2ee as Calendar object.
    everythings went fine, but what I have noticed when I print the Calendar object, the time came plus 3 hours later as the .NET time.
    FYI, I had checked the soap message that was received by embedded OC4J ,it was correct time, but the problem when you print it. and both .NET and Jdeveloper in the same machine
    example:
    <?xml version = '1.0' encoding = 'utf-8'?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <HelloWorldResponse xmlns="http://tempuri.org/">
    <HelloWorldResult>2008-10-14T10:40:21.12</HelloWorldResult>
    </HelloWorldResponse>
    </soap:Body>
    </soap:Envelope>
    when I printed the data, I got 2008-10-14T13:40:21.12
    so, does anyone have an idea about what is going on ??
    thanks in advance.

    ANY HELP :(

  • Encoding from UTF-8 encoded String to Microsoft Project default encode

    Hi Expert ...
    I have a problem with encoding a String from UTF-8 String in order to write a MPX (Microsoft Project) file. I used UTF-8 on my Database encoding, and I want to write a MPX file using MPXJ library, but the result is (?) character. I think it's because I didn't encode yet to Shift JIS (a Microsoft Product default encoding). And after that I try to encode the String with Shift_JIS encoding, but the same result is appeared. I try to looking another way, but there is no result.
    I hope some expert would help me to solve this problem.
    Thank you,
    Alfian B.

    Totally wrong. A String doesn't have an encoding.
    Now if you had an array of bytes, which were encoded using one charset, and you wanted to convert that to an array of bytes encoded using a second charset, you would use code like this:byte[] bytes = // the bytes encoded in UTF-8, let's say
    String s = new String(bytes, "UTF-8"); // make that into a String
    byte[] newbytes = s.getBytes("windows-31j"); // encode the String into windows-31j

  • Detecting character encoding from BLOB stream... (PLSQL)

    I'am looking for a procedure/function which can return me the character encoding of a "text/xml/csv/slk" file stored in BLOB..
    For example...
    I have 4 files in different encodings (UTF8, Utf8BOM, ISO8859_2, Windows1252)...
    With java I'can simply detect the character encoding with JuniversalCharDet (http://code.google.com/p/juniversalchardet/)...
    thank you

    Solved...
    On my local PC I have installed Java 1.5.0_00 (because on DB is 1.5.0_10)...
    With Jdeveloper I have recompiled source code from:
    http://juniversalchardet.googlecode.com/svn/trunk/src/org/mozilla/universalchardet
    http://code.google.com/p/juniversalchardet/
    After that I have made a JAR file and uploaded it with loadjava to my database...
    C:\>loadjava -grant r_inis_prod -force -schema insurance2 -verbose -thin -user username/password@ip:port:sid chardet.jarAfter that I have done a java procedure and PLSQL wrapper example below:
       public static String verifyEncoding(BLOB p_blob) {
           if (p_blob == null) return "-1";
           try
            InputStream is = new BufferedInputStream(p_blob.getBinaryStream());
            UniversalDetector detector = new UniversalDetector(null);
            byte[] buf = new byte[p_blob.getChunkSize()];
            int nread;
            while ((nread = is.read(buf)) > 0 && !detector.isDone()) {
                detector.handleData(buf, 0, nread);
            detector.dataEnd();
            is.close();
           return detector.getDetectedCharset();
           catch(Exception ex) {
               return "-2";
       }as you can see I used -2 for exception and -1 if input blob is null.
    then i have made a PLSQL procedure:
    function f_preveri_encoding(p_blob in blob) return varchar2 is
    language Java name 'Zip.Zip.verifyEncoding(oracle.sql.BLOB) return java.lang.String';After that I have uploaded 2 different txt files in my blob field.. (first one is encoded with UTF-8, second one with WINDOWS-1252)..
    example how to call:
    declare
       l_blob blob;
       l_encoding varchar2(100);
    begin
    select vsebina into l_blob from dok_vsebina_dokumenta_blob where id = 401587359 ;
    l_encoding := zip_util.f_preveri_encoding(l_blob);
    if l_encoding = 'UTF-8' then
       dbms_output.put_line('file is encoded with UTF-8');
    elsif l_encoding = 'WINDOWS-1252' then
       dbms_output.put_line('file is encoded with WINDOWS-1252');
    else
        dbms_output.put_line('other enc...');
    end if;
    end;Now I can get encoding from blob and convert it to database encoding and store datas in CLOB field..
    Here you have a chardet.jar file if you need this functionality..
    https://docs.google.com/open?id=0B6Z9wNTXyUEeVEk3VGh2cDRYTzg
    Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:34 PM
    Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:34 PM
    Edited by: peterv6i.blogspot.com on Nov 29, 2012 1:38 PM

  • Howto transmit UTF-Strings via URL?

    Hi there!
    I have to send UTF-String from an applet to an servlet using the get-method, so the whole data is transmitted using the URL.
    I may not use POST or something else, cause my applet should be 1.1 compatible.
    If I transmit standard-Chars like 'a', 'b' or '1' I dont have any problems - however with special characters like '�' or '�' I simply get unuseable although I use an URLEncoder/Decoder.
    Are there any ways to transmit UTF-Strings through an URL?
    Thanks a lot, lg Clemens

    Already found answer, sorry for the traffic...

  • [solved] [dwm] wrong encoding

    Hi,
    I have a few questions related to dwm:
    1.
    The titlebar of dwm gives me problems with umlauts (öäü). Its a fresh 2009.08-installation with dwm (5.6.1) as windowmanager.  Instead of umlauts funny symbols and letters are shown. I have the same problem with elinks, but I dont know if that is related.
    2.
    Is there a possibility to add the pertag-patch in 5.6.1? As far as I understand the patches are versionspecific and therefore I would have to wait for a 5.6.1 pertag-patch?
    3.
    Where do I have to put the programnames for autostarting programms in dwm? I want firefox, thunderbird, pcmanfm, geany a.s.o. to autostart everytime I invoke X and appear within their special tagspace, so I changed config.h accordingly.
    It would be cool, if anybody could help me
    Last edited by inknoir (2009-11-23 12:13:26)

    1. You either have a font that doesn't have such characters, or you have the wrong encoding. I'm using the standard "fixed" font in its "7x14" variant with a UTF-8 encoding, and umlauts look fine.
    2. Someone posted a current version of the pertag patch on the "dev" mailing list at suckless. I applied it. I'll post it as it applied for me, but I have other patches, so it might not apply cleanly for you, in which case, go search the mailing list archives.
    --- a/dwm.c Sat Aug 01 20:15:03 2009 -0400
    +++ b/dwm.c Sun Aug 02 17:26:12 2009 -0400
    @@ -120,25 +120,6 @@
    void (*arrange)(Monitor *);
    } Layout;
    -struct Monitor {
    - float mfact;
    - int num;
    - int by; /* bar geometry */
    - int mx, my, mw, mh; /* screen size */
    - int wx, wy, ww, wh; /* window area */
    - unsigned int seltags;
    - unsigned int sellt;
    - unsigned int tagset[2];
    - Bool showbar;
    - Bool topbar;
    - Client *clients;
    - Client *sel;
    - Client *stack;
    - Monitor *next;
    - Window barwin;
    - const Layout *lt[2];
    typedef struct {
    const char *class;
    const char *instance;
    @@ -270,6 +252,30 @@
    /* configuration, allows nested code to access above variables */
    #include "config.h"
    +struct Monitor {
    + float mfact;
    + int num;
    + int by; /* bar geometry */
    + int mx, my, mw, mh; /* screen size */
    + int wx, wy, ww, wh; /* window area */
    + unsigned int seltags;
    + unsigned int sellt;
    + unsigned int tagset[2];
    + Bool showbar;
    + Bool topbar;
    + Client *clients;
    + Client *sel;
    + Client *stack;
    + Monitor *next;
    + Window barwin;
    + const Layout *lt[2];
    + int curtag;
    + int prevtag;
    + const Layout *lts[LENGTH(tags) + 1];
    + double mfacts[LENGTH(tags) + 1];
    + Bool showbars[LENGTH(tags) + 1];
    +};
    +
    /* compile-time check if all tags fit into an unsigned int bit array. */
    struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
    @@ -1401,7 +1446,7 @@
    if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
    selmon->sellt ^= 1;
    if(arg && arg->v)
    - selmon->lt[selmon->sellt] = (Layout *)arg->v;
    + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = (Layout *)arg->v;
    if(selmon->sel)
    arrange();
    else
    @@ -1418,7 +1463,7 @@
    f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
    if(f < 0.1 || f > 0.9)
    return;
    - selmon->mfact = f;
    + selmon->mfact = selmon->mfacts[selmon->curtag] = f;
    arrange();
    @@ -1427,6 +1472,7 @@
    unsigned int i;
    int w;
    XSetWindowAttributes wa;
    + Monitor *m;
    /* init screen */
    screen = DefaultScreen(dpy);
    @@ -1458,11 +1504,31 @@
    XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
    if(!dc.font.set)
    XSetFont(dpy, dc.gc, dc.font.xfont->fid);
    + /* init tags */
    + for(m = mons; m; m = m->next)
    + m->curtag = m->prevtag = 1;
    + /* init mfacts */
    + for(m = mons; m; m = m->next) {
    + for(i=0; i < LENGTH(tags) + 1 ; i++) {
    + m->mfacts[i] = m->mfact;
    + }
    + }
    + /* init layouts */
    + for(m = mons; m; m = m->next) {
    + for(i=0; i < LENGTH(tags) + 1; i++) {
    + m->lts[i] = &layouts[0];
    + }
    + }
    /* init bars */
    for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
    w = TEXTW(layouts[i].symbol);
    blw = MAX(blw, w);
    + for(m = mons; m; m = m->next) {
    + for(i=0; i < LENGTH(tags) + 1; i++) {
    + m->showbars[i] = m->showbar;
    + }
    + }
    updatebars();
    updatestatus();
    /* EWMH support per view */
    @@ -1572,7 +1638,7 @@
    void
    togglebar(const Arg *arg) {
    - selmon->showbar = !selmon->showbar;
    + selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar;
    updatebarpos(selmon);
    XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
    arrange();
    @@ -1592,12 +1658,26 @@
    void
    toggletag(const Arg *arg) {
    unsigned int mask;
    + unsigned int i;
    if(!selmon->sel)
    return;
    mask = selmon->sel->tags ^ (arg->ui & TAGMASK);
    if(mask) {
    - selmon->sel->tags = mask;
    + if(mask == ~0) {
    + selmon->prevtag = selmon->curtag;
    + selmon->curtag = 0;
    + }
    + if(!(mask & 1 << (selmon->curtag - 1))) {
    + selmon->prevtag = selmon->curtag;
    + for (i=0; !(mask & 1 << i); i++);
    + selmon->curtag = i + 1;
    + }
    + selmon->sel->tags = mask;
    + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
    + selmon->mfact = selmon->mfacts[selmon->curtag];
    + if (selmon->showbar != selmon->showbars[selmon->curtag])
    + togglebar(NULL);
    arrange();
    @@ -1854,11 +1934,28 @@
    void
    view(const Arg *arg) {
    + unsigned int i;
    if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    return;
    selmon->seltags ^= 1; /* toggle sel tagset */
    - if(arg->ui & TAGMASK)
    - selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    + if(arg->ui & TAGMASK) {
    + selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    + selmon->prevtag = selmon->curtag;
    + if(arg->ui == ~0)
    + selmon->curtag = 0;
    + else {
    + for (i=0; !(arg->ui & 1 << i); i++);
    + selmon->curtag = i + 1;
    + }
    + } else {
    + selmon->prevtag= selmon->curtag ^ selmon->prevtag;
    + selmon->curtag^= selmon->prevtag;
    + selmon->prevtag= selmon->curtag ^ selmon->prevtag;
    + }
    + selmon->lt[selmon->sellt]= selmon->lts[selmon->curtag];
    + selmon->mfact = selmon->mfacts[selmon->curtag];
    + if(selmon->showbar != selmon->showbars[selmon->curtag])
    + togglebar(NULL);
    arrange();

  • Return arrary of objects from web service

    Hello ALL,
    This problem has stumped me for several days.
    I have a web service and a jsp client. the jsp client call the web service. the web service function return an array of object of DataBaseRecord type. I use XFire + MyEclipse + Tomcat to develop this project in a Linux box.
    the web service WelcomeYou is defined as follows
    {noformat}public List<DataBaseRecord> WelcomeYou(String ExampleDoc)
       List<DataBaseRecord> RetrievalResult = new ArrayList<DataBaseRecord>();
      //  Search relevant documents according to 'ExampleDoc' from a database
      //  The search result will be put into a RecordSet object 'rs'
       while(rs.next())
                  DataBaseRecord  NewRecord = new DataBaseRecord ();
                  NewRecord.RetrievedDocID = rs.getString("RetrievalDocID");
                  NewRecord.SimiScore =  Float.valueof(rs.getString("SimiScore"));
                  RetrievalResult.add(NewRecord );
    // I use the following for loop to see the content of RetrievalResult. I can see that the content is just what I expect. Additionally, the size of RetrievalResult is correct too.
    for(DataBaseRecord   databaserecord : RetrievalResult)
         System.out.println(databaserecord.RetrievedDocID + databaserecord.SimiScore);
      return RetrievalResult;{noformat}in a jsp file, the web service WelcomeYou is called
    {noformat}List<DataBaseRecord>  Result = new List<DataBaseRecord>();
    Result = srvc.WelcomeYou("some text ");
    // I use the following for loop to see the contentof Result, but each element of Result is empty. Moreover, the strange thing is that the size of Result is right.
    for(DataBaseRecord   databaserecord : Result)
         System.out.println(databaserecord.RetrievedDocID + databaserecord.SimiScore);
    {noformat}the class DataBaseRecord is defined as follows
    {noformat}public class DataBaseRecord{
        public String RetrievedDocID;
        public float SimiScore;
    {noformat}At the very end of the service function body(just before ' return RetrievalResult;'), i check the content of RetrievalResult using a for loop, it is correct.
    At the jsp file, immediately after the statement
    {noformat}   Result = srvc.WelcomeYou("some text ");
    {noformat}
    {code}
    , i check the content of Result using a for loop, it is incorrect except for the size of Result .
    I wonder where I am wrong in the above code.

    Can you show the UserProfile.java ? That may have some variables, which are not supported in web services.

  • Wrong encoding using "Mail" on iPad

    Sorry for bringing up an old issue - -
    the official Mail App seemed to be unable to handle the utf-8 correctlly.
    I encountered with the same problem like this thread:
    https://discussions.apple.com/thread/2811597?start=0&tstart=0
    I have sent a mail , using my Google Mail account , with Official Mail App.
    (I've forced my Google Account to use UTF-8 while sending mail.)
    The subject of mail is "メルタスチン" (which pronounced in Japanese sounds like "mail testing")
    And the content is "アスタイト" (which sounds similar to "as title")
    However I get the mail with wrong encoding type in MIME header:
    http://pastie.org/6081304
    (The pastie link is clean.)
    The subject and content is messed up for sure ,too.
    I don't think it's an exeption specified to GMAIL ;I've tested Yahoo!, Hotmail, GMAIL, and it's still not working properly.
    However, the mail route acted pretty wiered.
    Background:
    I'm in Taiwan , people here use Traditional Chinese(local common encoding:Big5), but I need to send a Japanese mail(common encoding Shift_JS).
    P.S.
    There was an thread on google forum about this issue ; yet there's no pratical soltution.
    http://productforums.google.com/forum/#!category-topic/gmail/reading-and-receivi ng-messages/60vin5HXlgs

    OxISBEh wrote:
    However I get the mail with wrong encoding type in MIME header:
    Try adding a special character to your message to force UTF8 in iPad Mail.  Try an emoji character from the emoji keyboard, or a dingbat via copy/paste from an app like Unicode Map (range 2700).

  • Return a flat file from an RFC

    Hi,
    I have created a function module that at the moment returns 4 tables. I want to create a flat file based on these tables and return that file from the function instead of the tables. I can create a flat file using the function GUI_DOWNLOAD.
    Is there a way to return a flat file from the function?
    Regards,
    Mark

    No, but you can return all four tables in single flat table.   First you would need to create a structure in SE11,  it would have one field, of type string.  In your function module interface, you would have a tables parameter like the structure that you just created.  No in the code of the function module, instead of writing your data of each internal table to the corresponding tables parameter to update the one table with the flat structure. 
    Make Sense?
    Regards,
    Rich Heilman

  • Human Workflow Task XPath query string returns multiple nodes.

    I am looking for trouble shooting help for this error. I am no sure if it is a server or jdev issue.
    I am running JDev version 10.1.3.3 and console version 10.1.3.1.0 locally.
    General information on the BPEL process:
    I have a temporary table in Oracle lite that I created items to be review by the user. I created a synchronous BPEL process. The first step in developing this process, I created the straight forward invoke the table to get the records, transform the records with a change the approve flag = "Y", and invoke the table to update the records. Works like a charm. I followed the online tutorial by dropping a human task after the transform, configured the parameters, setup the assignments, and moved the invoke to update table under the approved condition. If the table has only one record, the process runs great but if there are two records I get the following error message.
    <selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"><part name="summary"><summary>XPath query string returns multiple nodes.
    According to BPEL4WS spec 1.1 section 14.3, The assign activity part and query /ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr should not return multipe nodes.
    Please check the BPEL source at line number "178" and verify the part and xpath query /ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr.
    </summary>
    </part></selectionFailure>
    =================
    The error occurs in the first assign of the Human task after the assign copies the fields for the title. I underlined line number 178.
    <correlationSets>
    <correlationSet name="WorkflowTaskIdCor"
    properties="taskservice:taskId"/>
    </correlationSets>
    <sequence>
    <assign name="HumanTask1_1_AssignTaskAttributes">
    <copy>
    <from expression="concat(ora:getProcessURL(), string('/HumanTask1/HumanTask1.task'))"/>
    <to variable="initiateTaskInput" part="payload"
    query="/taskservice:initiateTask/task:task/task:taskDefinitionURI"/>
    </copy>
    <copy>
    <from expression="number(3)"/>
    <to variable="initiateTaskInput" part="payload"
    query="/taskservice:initiateTask/task:task/task:priority"/>
    </copy>
    <copy>
    <from>
    <payload xmlns="http://xmlns.oracle.com/bpel/workflow/task">
    <Case xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <CourtDate xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ErrorMessage xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ItemName xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <Payment xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <Zip xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ProcessFlag xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <LastUpdated xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <AddedDate xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <CityAttnyAmount xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ApprovalFlag xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ProlawKey xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    <ProcessKey xmlns="http://xmlns.oracle.com/bpel/workflow/task"/>
    </payload>
    </from>
    <to variable="initiateTaskInput" part="payload"
    query="/taskservice:initiateTask/task:task/task:payload"/>
    </copy>
    <copy>
    <from expression="concat(string('Item Fee Approval '), bpws:getVariableData('Invoke_1_Select_RecordsSelect_OutputVariable','TempItemCollection','/ns3:TempItemCollection/ns3:TempItem/ns3:ItemName'))"/>
    <to variable="initiateTaskInput" part="payload"
    query="/taskservice:initiateTask/task:task/task:title"/>
    </copy>
    <copy>
    <from variable="Invoke_1_Select_RecordsSelect_OutputVariable"
    part="TempItemCollection"
    query="/ns3:TempItemCollection/ns3:TempItem/ns3:ItemNbr"/>
    <to variable="initiateTaskInput" part="payload"
    query="/taskservice:initiateTask/task:task/task:payload/task:Item"/>
    </copy>
    <copy>
    Thank you for any help you can give me.

    Here is how I solved this problem: I was told by the metalink folks that I should use the same verion of SOA console as jdev. So I went back to jdev 10.1.3.1. Rather than reading from the Oracle lite table, I dumped the table into a flat file. I read flat file and populated the workflow. Remember to set the 'messages in batch' flag in the file adapter to 1 and the number of records to skip to zero in the format builder for the flat file. The process now reads each record and creates an instance for that each record. In other words, if I have 8 records in my flat file, I will have 8 instances of the process running on the console. Thanks Jeremy for your help figuring this out.
    Edited by: user7725126 on Nov 19, 2009 3:56 PM

  • Error: XPath query string returns multiple nodes

    Hi all,
    I am facing issue with the assign activity.
    Error message:
    com.oracle.bpel.client.BPELFault: faultName: {{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure} parts: {{ summary=&lt;summary>*XPath query string returns multiple nodes. The assign activity part and query are returning multiple nodes. The assign activity part and query named in the error message returned multiple nodes. It should return single node. According to BPEL4WS specification 1.1 section 14.3, the assign activity part and query named in the error message should not return multiple nodes. Verify the part and xpath query named in the error message at line number 2005 in the BPEL source*.
    BPEL code:
    <copy>
    <from variable="Invoice_Tax_loopCounter"/>
    <to variable="Var_Invoice_Tax_Contacts" part="payload" query="/ns30:Invoice_Tax_Contacts/ns30:Invoice/ns29:Get_InvoiceOutput[bpws:getVariableData'Invoice_Tax_loopCounter')]/ns29:ADDR_ATTRIBUTE2"/>
    </copy>
    We are using SOA 11.1.1.3 version.
    Any pointers on this?
    Thanks in advance

    Hi-
    This is because you are have multiple nodes either in source or target XML.
    My guess is some nodes of your XML might be repeating (means a single element/node has multiple values). Can you please check that or please post your XML here.
    Edited by: 145678 on Mar 7, 2011 6:28 PM

  • ObjectInputStream returns a wrong boolean value of a object

    ObjectOutputStream.writeObject once, then change the boolean value of the Contact object, ObjectOutputStream.writeObject again, but when ObjectInputStream.readObject, it returns SAME boolean values which should be different. can somebody explain me this? please. thx
       1. import java.io.*; 
       2. import java.util.*; 
       3.  
       4. public class TestSerializable { 
       5.      
       6.     /** Creates a new instance of TestSerializable */ 
       7.     public static void main(String args[]){ 
       8.         new TestSerializable(); 
       9.     } 
      10.      
      11.     public TestSerializable() { 
      12.         try{ 
      13.             Contact contact = new Contact("email","group",1); // contact.isOnline = true for default; 
      14.              
      15.             FileOutputStream fos = new FileOutputStream("ser"); 
      16.             ObjectOutputStream oos = new ObjectOutputStream(fos); 
      17.  
      18.             oos.writeObject(contact); 
      19.              
      20.             contact.setOnline(false); 
      21.             oos.writeObject(contact); 
      22.  
      23.             oos.flush(); 
      24.  
      25.              
      26.             FileInputStream fis = new FileInputStream("ser"); 
      27.             ObjectInputStream ois = new ObjectInputStream(fis); 
      28.             Contact ccRead1 = (Contact)ois.readObject(); 
      29.             Contact ccRead2 = (Contact)ois.readObject(); 
      30.              
      31.             System.out.println("ccRead1.isOnline() = "+ccRead1.isOnline()); 
    [u]  32.             System.out.println("ccRead2.isOnline() = "+ccRead2.isOnline() + " which should be FALSE. ERROR");  [/u]
      33.                        
      34.             oos.close(); 
      35.             ois.close(); 
      36.              
      37.         } 
      38.         catch(Exception e){ 
      39.             e.printStackTrace(); 
      40.         } 
      41.          
      42.     } 
      43.      
      44. } 
      45.  
      46.  
      47.  
      48.  
      49.  
      50. import javax.swing.tree.DefaultMutableTreeNode; 
      51. import javax.swing.tree.*; 
      52. import java.util.*; 
      53.  
      54. public class Contact extends DefaultMutableTreeNode { 
      55.      
      56.     private String email; 
      57.     private int arrayIndex; 
      58.     private String group; 
      59.     private boolean online; 
      60.      
      61.   
      62.     public Contact(String email,String group,int arrayIndex, boolean online){ 
      63.         this.email = email; 
      64.         this.group = group; 
      65.         this.setArrayIndex(arrayIndex); 
      66.         this.setOnline(online); 
      67.         this.setUserObject(this); 
      68.         this.setAllowsChildren(false);         
      69.     } 
      70.      
      71.     public Contact(String email, String group){ 
      72.         this(email,group,-1,false); 
      73.     } 
      74.      
      75.     public Contact(String email, String group, int arrayIndex){ 
      76.         this(email,group,arrayIndex,true); 
      77.     } 
      78.      
      79.  
      80.      
      81.     public String toString(){ 
      82.         return this.email; 
      83.     } 
      84.  
      85.     public String getEmail() { 
      86.         return email; 
      87.     } 
      88.  
      89.     public int getArrayIndex() { 
      90.         return arrayIndex; 
      91.     } 
      92.  
      93.     public String getGroup() { 
      94.         return group; 
      95.     } 
      96.  
      97.     public boolean isOnline() { 
      98.         return online; 
      99.     } 
    100.  
    101.     public void setOnline(boolean online) { 
    102.         this.online = online; 
    103.     } 
    104.  
    105.     public void setArrayIndex(int arrayIndex) { 
    106.         this.arrayIndex = arrayIndex; 
    107.     } 
    108.  
    109.      
    110. } 

    Did you try the reset() technique again?
    You could also have a look at ObjectOutputStream.writeUnshared().
    And it's not returning a 'wrong value', it is conserving the object graph of the original object sent, which is what it's specified to do and what it's supposed to do. If you don't want that behaviour use reset() or writeUnshared().

  • How do you return back one record from a NamingEnumeration

    how do you return back one record from a For Loop issue
    Posted: Jan 4, 2007 9:13 AM Reply
    I have the following piece of code and i want to be able to just return one item...
    that is return e.next(); but this line doesnt work for below what is wrong
    if (attrs == null) {
    System.out.println("No attributes");
    } else {
    /* Print each attribute */
    for (NamingEnumeration ae = attrs.getAll();
    ae.hasMore();) {
    Attribute attr = (Attribute)ae.next();
    System.out.println("attribute: " + attr);
    /* print each value */
    for (NamingEnumeration e = attr.getAll();
    e.hasMore();){
    System.out.println("value:- " + e.next()));
    return e.next();
    }

    At the end of the loop, the NamingEnumeration has no more elements. You need to call getAll() again.
    By the way, please use code tags (above the posting box). You've been here long enough to know that (judging by your registration date).

  • How to send a string to CVI .c and get string return through TestStand sequence?

    Hi, I am using TestStand 3.1 and I have the StringConverter.c with CVI 8.0 with the function:
    char * string_concat_2 (char* str1,char* str2)
     char * str_ret;
     str_ret = calloc(200, sizeof(char*));
     str_ret = strcat (str_ret, str1);
     str_ret = strcat (str_ret, str2);
     return str_ret;
    I would like to use it  through Teststand, so I add a sequence using 'StringValueTest'. I Spectify Module CVI &  link to StringConverter.c and type in Function Name: char * string_concat_2 (char* str1,char* str2)
    1. How I define to send the string1 ("Hello") & string2 ("World") to the Module?
    2. How I define to string return ("HelloWorld" from the Module?
    Thanks

    Hi plit string,
    You will need to have a parameter passed by reference to return the
    string.  To do this, use a "C String Buffer" instead of a "C String
    (const)" parameter type.  There is documentation on this in TestStand
    Help.  Here is a quote from there:
    "When using string parameters, use the C String Buffer or Unicode
    String Buffer type if you want the function to be able to change the contents of
    the argument in TestStand. Use the C String or Unicode String type if the DLL
    function does not modify the argument. You can pass a literal string, a
    TestStand string property, or an expression that evaluates to a string as the
    value of a string parameter."
    Gavin Fox
    Systems Software
    National Instruments

  • Format string returned by PieChart labelFunction

    I am new to Flex and found this web page with an example Pie
    chart:
    Pie
    chart example with code
    I want to format the output so that, using this link as an
    example, the country is in a larger, bold font. I sure appreciate
    any thoughts or tips.
    Thanks

    Thanks for the reply. There is an ItemRenderer for PieSeries,
    but I do not understand how that would be extended/replaced to
    format the string returned from my custom labelFunction to changed
    font characteristics. I looked at htmlElement, but it does not
    appear to be a solution for this case.
    To be clear and referring to the link from my initial post,
    instead of displaying this default output from the label function:
    USA:
    Total Gold: 35
    37.23%
    I want:
    USA:
    Total Gold: 35
    37.23%
    Where the "USA:" string is bold. It seems very simple, but I
    am unclear on how to proceed. Any ideas?
    Thanks.

Maybe you are looking for

  • Text Messaging Error & Software Update Error

    I got the Blackberry Q10 on Saturday (6.17) and had some issues with text messaging, so I went to Verizon last night (6.17) after two days of having issues. They gave me another blackberry Q10 in hopes that my original phone just had a glitch in it,

  • Book Printing Quality

    I just finished a photo book in Aperture and thinking of getting it printed through Apple (Kodak). Before sending, I would like to get some input on the book quality. Is it professional quality or .... ? ? ? Any comments will help me make a decision

  • I can´t access to itunes store in the ipad after install ios7

    I can´t access to itunes store in the ipad after install ios7

  • Updating a frame / use of static variables

    Hello, I am working with a program (installer) that walks the user through a series of question/response frames. My first question has to do with refreshing the frame with the new contents whenever an event is triggered by a button. I have a method t

  • Setting up replication with client written in C++ and DB master in Java

    Hi I am trying to write C++ client that will join replicated environment created by a master written in java. For JAVA, I am using Berkley DB Java 4.0.103 API. So far, I have written Master in java which creates a replicated environment. I also have