aspose file tools*
The moose likes Servlets and the fly likes How to pass data to a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to pass data to a servlet" Watch "How to pass data to a servlet" New topic
Author

How to pass data to a servlet

Michael Kruger
Greenhorn

Joined: Jul 27, 2011
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61066
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Kruger
Greenhorn

Joined: Jul 27, 2011
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61066
    
  66

There's only so much room for parameters on a GET. Switch to POST if you are exceeding it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass data to a servlet