• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How send file data to JSP/Servlet page and save to disk?

 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that will open a socket to a web page (A Servlet or JSP), get the bytes of a file and send that file data (along with file name, username and password) to the servlet/jsp. I want the server-side code to then take that data and save it to disk as that filename. How would I do this?
I'm figuring I'd use either POST or PUT on the client-side for the command sent to the server? How do I set up a servlet to handle a PUT request? Can i send other info with a PUT request?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you considered a jsp/servlet that responds to multi-part requests (with say a package like com.oreilly.servlet)?

Get this part working with a plain HTML page that POSTS to the servlet, the filename, username and password in plain text fields, and the file data in a file upload field.

Then use a packet sniffer to determine the format of a multi-part POST and use this info to construct your own POST from the application over the socket.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe I get what you're saying. You just mean, send all the commands that a browser would for a POST, right? So simulate a browser post with my socket app. Am I reading that correctly?
That sounds fairly easy if that's what you're thinking, I just need to know the commands (The socket is in VB, the web server is tomcat)
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I meant, yes.

I'd sniff the packets as they came through and simply construct a byte stream, or the VB equivalent that mimics the format of a multi-part post.

I did it once, and posted the results here
[ March 21, 2003: Message edited by: Mike Curwen ]
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I know what the posted info looks like on the server side (I've written a parser for that before), but what does the client-side code command look like? That I don't know because JSP doesn't let you see it (that I know of).
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you mean by "code command".

Unless I'm gravely mistaken, what you get on the server-side is exactly what was sent from the client. You would construct a sequence of characters that exactly duplicates the sequence of characters that you can sniff on the server-side.

Send that sequence of characters through a socket that connects to the correct IP and port, and it should be understood on the other end as "aha, an HTTP request".

Whatever is listening to port 80 is expecting HTTP requests. And as long as the packets that it receives can be decoded to look like "POST http://205.200.230.44:8080/ee/edit HTTP/1.0\n", etc, etc... then that is the 'command'.

If you mean the command to send this sequence of characters, I don't know.. you're doing it in VB right?

Hopefully Bill Brogden will notice this thread and butt in if I'm wrong (or anyone else).
[ March 21, 2003: Message edited by: Mike Curwen ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike - if I understand whats required, you are on the right track. (Of course if he wanted a Java application he could use the HttpURLConnection.)
Bill
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you're right on. It's weird but my browser wasn't showing your code in full. I didn't see the headers. Thanks for posting it!
But my one question: how do I generate a proper boundary (delimiter)?
[ March 21, 2003: Message edited by: Robert Paris ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the other post that I linked to ( this post ), the 4th post to that thread is me showing how to use \r\n, and it also shows you what a boundary looks like.
[ March 22, 2003: Message edited by: Mike Curwen ]
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, but I mean how do I generate the boundary. I mean I could just reuse the boundary you provided, but I'd prefer to generate one each time so they're unique (in case there's a need some time for uniqueness)
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic