Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet image upload problem

 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day everyone and thanks for help rendered so far.
Please scholars,this my servlet code is displaying an 4 errors as shown below
and i need your help




Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\esedos>cd C:\Tomcat 6.0\webapps\form2\WEB-INF\classes

C:\Tomcat 6.0\webapps\form2\WEB-INF\classes>javac UploadFile.java
UploadFile.java:62: illegal character: \8211
int boundaryLocation = file.indexOf(boundary, pos) û 4;
^
UploadFile.java:73: illegal character: \8211
fileOut.write(dataBytes, startPos, (endPos û startPos));
^
UploadFile.java:73: not a statement
fileOut.write(dataBytes, startPos, (endPos û startPos));
^
UploadFile.java:73: ';' expected
fileOut.write(dataBytes, startPos, (endPos û startPos));
^
4 errors




The servlet code is stated below












Please also check my html code as my database has 2 columns; fname with varchar and image with blob
and i dont know the way i referenced them in my servlet and html is correct.

Thanks and regards

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at your post, you can actually see the invalid characters. Those are not minus signs, but some other character that looks like a minus sign:

UploadFile.java:62: illegal character: \8211
int boundaryLocation = file.indexOf(boundary, pos) û 4;

UploadFile.java:73: illegal character: \8211
fileOut.write(dataBytes, startPos, (endPos û startPos));
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Word or WordPad to write code?
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Mr.Dittmer and Mr. Bibeault for your wonderful help.
Regarding the code I remove the -sign and add +sign and the error gone.
But the problem now is that when i run the program using URL




it returns an empty page instead "success your file is saved" which infers that the image is not uploaded into the database.

my web.xml is as follow



I have only 2 columns in my table; fname column which has datatype "varchar" and image which has datatype "longblob"
my html file has cloumn name as shown below which corresponds with the 2 column name i have in the database and yet
the image upload is still problematic. Please Sir, help me .Rargards and God bless.



ie name="fname" and name="image"

 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your code now compiles, but it doesn't do what you expect.

That may be because you changed the logic; it would have been better to replace the bogus minus signs by real minus signs, instead of plus signs, in my opinion. But anyway there's a good chance your code threw an exception. Have a look on the server and see if it did. There should be logs where stack traces go.
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very muc sir but i am ineffective in solving this problem
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please sir i hav gone through the code and i dont know what to do. Please check if the column name
"fname and image" that i used in my database is incorrect with the code .I guess the problem can equally come from using incorrect columname .Please sir help me check
Thanks and Regards
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul said:
Have a look on the server and see if it did. There should be logs where stack traces go.

Do you know what log files are, and where to find them on your server?
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you i have seen it and what the problem is all about
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic