Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass data to a servlet

 
Michael Kruger
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a neophyte in Java and need some direction in writing a servlet. Thank you in advance for any assistance.

I am calling a servlet from an Adobe Flex front-end to generate a Jasper Report. The back-end is Rails and has created a complicated (and voluminous) XML data structure that I need to get to the servlet. Flex has a facility to send "variables" attached to the request (which I have as a "GET" but could be changed to a "POST"). If I have Flex serialize the data into a file and have the servlet read the file from disk it works fine but I don't want to write a file if I can help it. Other than disk maintenance, it just seems inelegant and to be a dirty work-around.

The working code is:


I've tried "request.getParameter()" which returns a string that I can get into a stream but the data is too large and Tomcat errors out.

I've tried "request.getAttribute()" which returns an object but I can't seem to get that to a BufferedInputStream. Actually, I haven't gotten any compiled Java code in this attempt so I really don't know that there even IS an "attribute".

Being such an ignoramus in Java (and, for that matter in HTTP), after 5000 Googles I haven't been able to find a way to get the data to the servlet as something other than a Parameter and convert it to a stream. I know Java must have a way to do it and that it's probably simple. I think I must just have the wrong mindset and approach and am looking in the wrong direction.

Please point me down the correct path.

thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a GET is being issued correctly with request parameters in the query string, getParameter() will retrieve them; everything else you've tried is a red herring.

If getParameter() is not retrieving the value, the problem is in the request, not in the servlet. You need to spend your time finding out why the GET isn't being correctly issued.
 
Michael Kruger
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for getting back so quickly, actually I'm amazed you responded so fast.

The parameters are actually getting through to the servlet (I also pass a client number and a company name for report header variables and the servlet gets them through "request.getParameter" and will print if I don't try to send the XML). It's the size of the XML data structure that creates the problem using getParameter. The error I get is a 414 "Request-URI Too Large".

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's only so much room for parameters on a GET. Switch to POST if you are exceeding it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic