Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Upload code in Java Servlet not working on Apache tomcat 5.0 on Linux platform  RSS feed

 
Prg Lakshmi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code for uploading file in JSP/ Servlet using DataInputStream works well on Windows 7 running Apache Tomcat 7.0 (7.0.23) and uploads file correctly. But the same code when run on Apache Tomcat 5.0 in Linux platform is creating file of 0 bytes. The ownership and permissions of the folder to which files are getting uploaded have also been set but still gives the same problem. Please help.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for possible exceptions that could be happening on linux in the log files, make sure you are not hiding the exceptions to see them.
If you can't see them then post the code that you are using.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you could show us the code?
 
Prg Lakshmi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP file gets the filename to be uploaded.

The Servlet code for Uploading file is as follows:

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, don't ignore the exception - print the stack trace to where you will see it; how else will you know if anything goes wrong? That applies to the exceptions in lines 59 and 124.

Two more points that have nothing to do with the problem at hand, but are strongly recommended best practices: 1) use PreparedStatement for interfacing with a DB instead of interpolated strings, and 2) GET and POST are not interchangeable. Any code that treats them as such (like this one) breaks the HTTP specification. A file upload should be a POST, never a GET.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!