Parse String to Object

Hello,
I passed an object as a parameter (in a url) in a jsp form to a servlet.
As http only accepts text, the servlet gets the object as a String.
How can I parse the info back to an object in the server side? Is that possible, anyway?
Thanks,
Al.

You'd be better off assigning a unique id to the object, passing that unique id to the jsp, and using the unique id in the servlet to retrieve the object (obviously you'd have to store the object in a map whose key is the unique id).
Sorry for saying unique so much.

Similar Messages

  • Parsing String

    i have problem to parse string to document
    i have string like this str = "<root><data>1</data><data>2</data><root>";
    how to parse this string in docoment xml

    import java.io.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    public class PrettyPrinter {
       public static void main(String[] args) {
            // Assume filename argument
            String filename = args[0];
            try {
                // Build the document with SAX and Xerces, no validation
                SAXBuilder builder = new SAXBuilder();
                // Create the document
                Document doc = builder.build(new File(filename));
                // Output the document, use standard formatter
                XMLOutputter fmt = new XMLOutputter();
                fmt.output(doc, System.out);
            } catch (Exception e) {
                e.printStackTrace();
    }The above code is taken directly from
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom-p2.html
    u don't have to use Factories, this is what is said in that excerpt, it is very easy to use, and it is said that 80 % of the xml work can be done with 20 % or less work using JDOM.
    n joy ....
    </ksenji>

  • Purpose of request.setAttribute(String parm1, Object parm2)

    HttpServletRequest request.setAttribute(String parm1, Object parm2) vs. HttpSession session.setAttribute(String parm1, Object parm2)
    hi
    can anybody please explain to me what does HttpServletRequest request.setAttribute() do? and for what purpose is it used for?
    i already know that HttpSession session.setAttribute(String parm1, Object parm2) is used to bind a session to a variable, so that it can be accessed throughout the servlet application.
    thanx
    shankha
    ps: please correct me if i'm wrong

    shankha,
    What does the API doco say?
    I think it just sets a request scoped attribute... ie a request parameter.
    This looks pertinant: http://www.rgagnon.com/javadetails/java-0401.html

  • How to parse string to date in j2me?

    How to parse string to date in j2me?
    Please help me.

    Hi..
    String dyStr = "20";
    String mtStr = "1";
    String yrStr = "1999";
    Calendar cal = Calendar.getIntstance();
    int dy = Integer.parseInt(dyStr);
    int mt = Integer.parseInt(mtStr);
    int yr = Integer.parseInt(yrStr);
    cal.set(Calendar.DATE, dy);
    cal.set(Calendar.MONTH, mt);
    cal.set(Calendar.YEAR, yr);
    OK?

  • Conver a string to object?

    hi, I am having problem converting string to object, then store the object into a object linklist node. I debugged it to make sure that everything the user types got stored in the string, but when the debug reaches "obj = temp;". obj doesn't have any value. why is that??
    String temp;
    Object obj;
    //have the user input something to the string. then...
    obj = temp;
    temp = (String) obj;
    ObjNode.insert(obj);
    Thank you...

    well, it's one of my assignment. have to write a class of object circular linked queue with a main funtion to test it. in the main function, I have to somehow store the object into the object node, but I havn't learned how to read object, only string. so I am tring to read string then change to object and store it. but if you could tell me how to just read object, it would be much easier for me.
    thank you.

  • String to object?

    Hi,
    I have a problem in converting string to object.
    The way I intended to do is like this:
    String a1 = "John";
    String a2 = "Smilth";
    String a3 = "Eric";
    String a10 = "Howard";
    and I wanna assgin the value of a1 ~ a10 into a temp string.
    like this;
    for (int i = 1; i<= 10; i++)
    String tempString = "a" + i; //assign the value of original string into tempString.
    // bla bla bla
    I know I have to use class.forName() to get what I want, but I have no clue on how to
    implement this in detail. Any help will be great appreciated.
    Thanks
    TC Wang

    May I ask why you do it so complicatec? Why don't you use an array?
    String[] a = new String[10]
    a[0] = "John";
    a[1] = "Smilth";
    a[2] = "Eric";
    a[9] = "Howard";
    // arrays start with zero, but 0 to 9 are also ten entries just
    // like 1 to 10.
    for (int j = 0; j <= a.length; j++)
        String tempString = a[j];
        // Here goes your other code
    // I replaced i with j, because i surrounded by round brackets
    // means printing text cursive on this BBS board

  • How could i parse string and link its model with my files in eclipse project?

    How could i parse string and link its model with my files in eclipse project?, as i read that we dont have to use standalone mode while working with eclipse projects.
    Example of what i want to do:
    I have file1.dsl in my project which contains some statements but the declaration of these statements are not in another file, i need to put them only in my code

    Hi Stefan,
    I have eclipse project contains 2 files, file1.dsl and file2.dsl, you can see the contents of the files below.
    file1.dsl contains some statements as shown below and file2.dsl contains the declarations of the variables. (like in C++ or Java we have declarations and usage)
    At this step file1.dsl and file2.dsl will be parsed successfully without any errors.
    Lets imagine that we will delete this project and will create another one and the new project will contain only file1.dsl (which contains the usage)
    At this step this file (file1.dsl) will contains some errors after parsing it, because we are using variables without declarations.
    So what i need is to parse the content of file2.dsl directly without adding this file to the project.
    I need to add the content of file2.dsl directly as a string in the code and parse it. just like that ( "int a;int b;" )
    And link file1.dsl with the model generated after parsing my string
    file1.dsl
    a++;
    b++;
    file2.dsl
    int a;
    int b;
    Thanks

  • Trouble parsing string

    I need to parse strings in the format "City State
    Abbreviation Zipcode" (ie "Glenview, IL 60062") to seperate them as
    their own variables. Problem is that sometimes there is a comma
    after city, sometimes not, so I've resorted to REfind to seperate
    the string. Here's the snippet, "city" is the entire string I
    mentioned above. The problem is that the refind I use seems to be
    returning 0. I'm trying to find the two capital letters that
    designate the state abbeviation.
    <cfif city neq ''>
    <cfset crpos = refind("[:upper:][:upper:]",city) >
    <cfset zip = trim(right(city,len(city)-crpos))>
    <cfset citystate = trim(left(city,crpos)) >
    <cfset newpos = find("#chr(32)#",citystate) >
    <cfset state =
    trim(right(citystate,len(citystate)-newpos)) >
    <cfset actualcity =
    trim(left(citystate,len(citystate)-newPos)) >
    </cfif>

    I probably should mention some explaination about what the
    regular expression is doing:
    Note: Groups are RegExp statements surrounded by ()
    Group 1: Combination of Letters and Spaces (e.g. City Name)
    optional comma and (required) space
    Group 2: 2 Character upper case state code (State Code) (note
    - depending on your source, state codes may not always be upper
    case)
    (required) space
    Group 3: 5 digit string (e.g. Zip Code) (note - again,
    depending on your source, you may be getting 5 digit zip + 4 or
    even non-us zip codes that may involve alpha characters.)
    The replace function is using back references to refer to the
    text matched by group 1,2 and 3.

  • Split Function unable to parse string correctly

    Hi,
    I'm using split function to split string into multiple rows using comma "," as delimiter. In a string I have following values which are not parsed correctly as they have comma inside the values. 
    American Dawn, Inc.
    Battalian USA, Inc.
    Fria USA, Inc.
    Lazer, Inc.
    Mexilink Inc.
    Is there any other approach to fix this issue?
    Here is the split function Im using:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(MAX), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(MAX) NULL 
    As 
    Begin 
    Declare @item varchar(MAX), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final
    delimiter 
    Select @List = @List + @Delimiter -- get position of
    first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos
    -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List)
    - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    Another user in this forum posted a split function that
    he wrote:
    CREATE FUNCTION dbo.splitter(@string VARCHAR(MAX), @delim CHAR(1))
    RETURNS @result TABLE (id INT IDENTITY, value VARCHAR(MAX))
    AS
    BEGIN
    WHILE CHARINDEX(@delim,@string) > 0
    BEGIN
    INSERT INTO @result (value) VALUES (LEFT(@string,CHARINDEX(@delim,@string)-1))
    SET @string = RIGHT(@string,LEN(@string)-CHARINDEX(@delim,@string))
    END
    INSERT INTO @result (value) VALUES (@string)
    RETURN
    END
    GO
    Both of them are unable to parse above values incorrectly.
    FYI:  String is made of values that are selected
    by user in SSRS report. I think SSRS when combine values , put comma "," between multiple values.
    Any help or guidance would be appreciated.
    ZK

    duplicate of
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/820ac53c-ce25-4cc7-b828-5875a21d459d/split-function-unable-to-parse-string-correctly-in-ssrs-report?forum=sqlreportingservices
    please dont cross post
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Hi to parse String "x;y:z" in Core Java

    hi to parse String "x;y:z" in Core Java

    Deepak_A_L wrote:
    how do i parse a String "X;Y:Z" in java i.e the results of parsing the string
    String s = "X;Y:Z"
    in terms of ENGLISH LANGUAGE -->(X Semicolon Y Colon Z)
    should be the below o/p individual Strings.
    X
    Y
    Z
    how do i get the above output.????Split on a semi- or regular colon using String's split(String regex) method.

  • Parsing a string to object attribute's

    My string will be delimited by tab spaces. I need to parse the contents of the string then assign these to the attributes on an object. The solution I believe would similar to this String to Vector method:
    public Vector stringParser(String inString) {
         //Local variables.
         int lastIndex = 0;
         Vector retVector = new Vector();     
         int theCount = 0;
         int indexOf = inString.indexOf( dConstants.DVX_CHAR_SEP );
         //Keep on looping until there are no more DVX_CHAR_SEP
         while( indexOf != -1 && lastIndex != indexOf ){
              retVector.addElement( new String( inString.substring( lastIndex, indexOf - 1 )));
              lastIndex = indexOf;
              indexOf = inString.indexOf( dConstants.DVX_CHAR_SEP, lastIndex + 1 );
         }//while there are DVX_CHAR_SEP's
         //The last bit of string will not be DVX_CHAR_SEP terminated. Grab it now.
         if( indexOf == -1 ){
         //Just in case there weren't any DVX_CHAR_SEP.
         indexOf = 0;
         retVector.addElement( new String( inString.substring( indexOf, inString.length()) ));
         return retVector;
    NB. public final char DVX_CHAR_SEP = '\t';

    And your question is...?
    (By the way, I generally use a StringTokenizer to do exactly that.)

  • Parsing String to date

    This is my function to convert a string into a desired output format.But my Date in the desired output format is coming out to be null.Could smeone plz point out my mistake.
    Date getDateInDesiredFormat(String strInputDate,String strInputFormat,String strOutputFormat)
         try
           SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
           SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
           ParsePosition pos = new ParsePosition(0);
           Date dtInputDate=sdfInput.parse(strInputDate.trim(),pos);
           System.out.println(dtInputDate);
           String strFormattedDate=sdfOutput.format(dtInputDate);
           System.out.println(strFormattedDate);
           Date dtOutputDate=sdfOutput.parse(strFormattedDate.trim(),pos);
           if(dtOutputDate==null)
                System.out.println("dtOutputDate is null ");
           else
               System.out.println(dtOutputDate.toString());
           return dtOutputDate;
         catch (NullPointerException npex)
             return null;
          catch(Exception ex)
              return null;
       }This is how i am calling the function
    Date date=getDateInDesiredFormat("Fri Sep 30 20:30:56 IST 2006","EE MMM d HH:mm:ss ZZZ yyyy","MM-dd-yyyy");
      }

    You need to use the sdfInput object to parse the date and sdfOutput to format and print it (like you did before your 'if'):
    SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
    SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
    Date dtInputDate=sdfInput.parse(strInputDate.trim());
    String strFormattedDate=sdfOutput.format(dtInputDate);
    System.out.println(strFormattedDate);the toString() you use in the else block uses a default format, not the one you specify.

  • Making Strings an object of a class

    Okay hello. Now i have LinkedList<Customer> customers = new LinkedList<Customer>();now i am trying to add a string into this list. i know this is not possible as the list that i made is of type object.
    My question is how do i make a string into an object so that it can be added into the list.
    String l = (Customer) x;i know this is wrong that is why i am asking how do i make the string so that it can be added into the list of customers. Customer is a class. Does the conversion of String to Customer object meant to be done in that class?? please help

    That String is an input. Thats the problem im having. As it is a string that im inputing the customers.add(l) doesnt work. for example, foreget the String l = (Customer) x. We have concluded this doesnt work. But when i do String l, the cusomters.add(l) comes up with an error. The error is it cannot find add(). This way the add() is just some ordinary one and not of the Liked List type. Therefore simple putting String l; is inefficient for the list to work, thus i need to make a parser so that the String becomes of type Customer. But i do not know how to make the parser, or even where to start. I have seen one that made double into string, but not object to string. are the ways these 2 are done similar?
    import java.io.*;
    import java.util.*;
    public class Customers implements Serializable
    {   private LinkedList<Customer> customers = new LinkedList<Customer>();
        Customer x;
        String z;
        double y;
        String l;
        public void add()
        {   System.out.println("Add a customer");
            l = Store.nextLine();
            customers.add(l); }

  • Parsing & handling of object and param tags

    Hi all,
    I'm working on allowing people to paste certain embedded video code into a wysiwyg / html editor we've built with the help of (amongst others) javax.swing.text.html.HTMLWriter.
    I'm facing the following problem here:
    When i try to parse the <object><param></param></object> piece, it removes the <param> tags, and incorporates these in the <object> tag. For example:
    <object width="300" height="250"><param name="allowscriptaccess" value="always"></param></object>becomes:
    <object width="300" height="250" allowScriptAccess="always"></object>All param tags get converted into the object tag as String attributes. Problem with this is that the allowScriptAccess attribute is not a valid attribute of the object tag.
    Is there any way to prevent this conversion so it will retain the <param> tags?
    Thank you in advance.
    Edited by: Floxxx on Dec 28, 2009 10:16 AM

    This seems to be default behaviour in HTMLWriter, function Write().
    There it retrieves all elements with their attributes. The attributes summed up in the param tags show up as attributes for the object tag.
    Edited by: Floxxx on Dec 28, 2009 10:54 AM

  • DateFormat.parse(String)

    can anybody tell me why I don't get a SHORT format:
    import java.util.*;
    import java.text.*;
    public class MyDate{
       public static void main(String[] args){
          Date date = makeDate("04/22/2003");
          System.out.println(date); // what i get looks more like FULL
        public static Date makeDate(String dateString){
           Date date = null;
           try {
              DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
              date = fmt.parse(dateString);
          catch(ParseException e) {}
          return date;
    }Thank you.

    what I think is tripping you up is that a java.util.Date is not a String. It looks like you're thinking that you can format a java.util.Date object and somehow it is "11/23/2004" (or whatever) - but it's not - it's just a number. So, you have this String that you want to convert to a java.util.Date (which you correctly did with the parse method of the DateFormat class) but then you turn around and want to convert that java.util.Date to a String so you can put it into a List, so why not just put the original String into your List? Is it because you want to change the format? Fair enough, then you can use two DateFormat implementations, one to parse the incoming String to a Date, then the other to format the Date to the format you want. Or is it so you can do the sort chronologically? If that's the case, then you can write up a Comparator to do that, or you can store Dates in your list, sort them, and when it comes time to display this thing (if you ever do that) use a DateFormat implementation to convert those to a formatted String.
    Make sense?

Maybe you are looking for