Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing array from servlet to java

 
George Botsaris
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys
I am writing a game in J2ME. In this game i am using a servlet to communicate with my database in which i store my online highscores.
When a player wants to view the online highscores a servlet loads the highscores from my mysql database and saves them in an array. I would like to send this array from my servlet to my java program. Can this be done???
Can i send an array using the responce parameter of the servlet? If yes how can i retrieve it from my application?
Thanking you in advance
George Botsaris
 
Chad Clites
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite understand your question. Are you trying to pass the array to a client side app, or a server side app? If it is server side, you just need to declare an instance of your class, and pass the array as a parameter like you normally would.

Or am I misunderstanding your question? (little low on caffeine this morning)
 
George Botsaris
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send an array with my highscores from a servlet to a client side app(my J2ME game).As i understand i have to use the 'HttpServletResponse responce' in my doGet method in my servlet to do that. Is it possible to pass my array as a parameter and then read it somehow in my J2ME game?
Thanks for your help
 
Chad Clites
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm.. I thought that someone who actually knew how to do this would have responded by now, because I have never done anything like this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do know that it's possible to return a serialized java object in a servlet response (for consumption by an applet). There are several articles on this available on the web. http://www-128.ibm.com/developerworks/java/library/j-tunnel/?dwzone=java

I haven't commented earlier because I don't know enough about J2ME to say whether or not it is capable of deserializing the object on the client end.

Say the word and I'll move this to our J2ME forum for you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64183
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the servlet hit being initiated by the client application? If so, how? You're not being very clear about the mechanisms you are using.

Most likely, you'll need to return the data as the body of the reponse. Perhaps as XML?
 
George Botsaris
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your responce guys
I managed to send my highscores from the servlet to my app by opening a connection and sending one highscore eachtime.
So if i have 10 highscores in my database i will have to open a connection 10 times, each time sending a different highscore from my servlet to my app as a string.
I dont know if thats very wise, but thats the only way i could thought.
Thanks again for replying
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64183
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's nice when someone asks a question and completely ignores the replies.
 
George Botsaris
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didnt mean to be rude, but i found an alternative way to do the job and moved on with my project
Thanks again for showing interest in my post
 
amr gamal
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Botsaris wrote:I didnt mean to be rude, but i found an alternative way to do the job and moved on with my project
Thanks again for showing interest in my post



Can you tell me this way please ?
because I'm falling in the same problem.
 
Eamonn Moloney
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I know this is a bit late but I just found the post today. You could seralise the java object in the servlet and then deseralise it on the client however that can be quite limiting. A nicer way would be to send the scores back to the client as xml or json. An XML parser comes with j2me or you can use one of the many json parsers available such as https://launchpad.net/j2me-json

The basic idea is to have you client make a request to the servlet and have your servlet return the xml or json formatted response. Set your array in the request attribute and forward the servlet to a JSP. Then use JSTL to render the JSP.

Another alternative... albiet more complex solution is the apache thrief project. If you are planning an iPhone, android, j2me, javascript version of you app it would be very well suited to fit your needs.

http://thrift.apache.org/
 
amr gamal
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've found an easy way, just putting the array elements in a string separated with delimiters.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic