Results 1 to 3 of 3
  1. #1
    hussainzim is offline Member
    Join Date
    May 2008
    Posts
    14
    Rep Power
    0

    Default how to pass a List from a servlet to javascript..

    hi..i want to pass a LIST from a servlet to a javasciprt whioch im usiong ajax..example of my code is given below..thnak u in advance..

    servlet

    Java Code:
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    		// TODO Auto-generated method stub
     
    	res.setContentType("text/xml");
            
            res.setHeader("Cache-Control", "no-cache");
            
            
            
            //get parameters store into the hashmap
            HashMap paramsMap = new HashMap();
            Enumeration paramEnum = req.getParameterNames();
            while(paramEnum.hasMoreElements())
            {
                String paramName = (String)(paramEnum.nextElement());
                paramsMap.put(paramName, req.getParameter(paramName));
            }
            //get the author name passed
            String authorName= (String)paramsMap.get("author"); 
     
            
            List list= DataAccess.getAuthorPaperDetails(authorName);
    		
        
    		}

    javascript

    Java Code:
    function callbackUsername() {
        
        if (req.readyState==4) {
         
            if (req.status == 200) {
           
                *//i want to get the LIST here//..*
            }
            else
            {
            	
            }
        }

  2. #2
    sagarbirari is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    hello,

    In your servlets get method ,get PrintWriter out object.
    then thr enumaration appent all list value in one String object with delimeter say comma(,).
    then write following command
    out.print(str);
    means String
    ------------
    In your Java scriptcode

    function callbackUsername() {

    if (req.readyState==4) {

    if (req.status == 200) {

    *//i want to get the LIST here//..*
    var str = xmlHttp.responseText;
    }
    else
    {

    }
    }

    xmlHttp is ajax variable.



    Regards

  3. #3
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default

    I think we can send only String as response to a Ajax call... Not sure though... If i'm correct then put the entire list in a String with proper delimiter and you can split them in your xmlHttp.responseText...

    fREDDIE

Similar Threads

  1. Question on how to pass text of a pulldown
    By Brucifer in forum New To Java
    Replies: 0
    Last Post: 04-02-2008, 11:23 PM
  2. Pass by ref. A work around?
    By diRisig in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 07:25 PM
  3. how to pass array in java?
    By sivasayanth in forum New To Java
    Replies: 3
    Last Post: 01-13-2008, 04:33 PM
  4. Cannot pass the correct property value to a form
    By piterskiy74 in forum Web Frameworks
    Replies: 0
    Last Post: 12-11-2007, 03:17 PM
  5. How to pass an html variable as an applet value
    By fred in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 03:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •