• Post Reply Bookmark Topic Watch Topic
  • New Topic

inputstream reading wrong file when a url is passed.  RSS feed

 
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am working on a web project. now the task is as follows:

i have a webpage on hosted on localhost. i have a page which i upload to it and put it in a specified location using a servlet. now i have a java class which has to read this uploaded file, i get the path of the uploaded file from servlet and create an inputstream using it. I have tested that the file is available through the context path.

my problem is that no matter what html file i upload, the inputstream is only showing the login.html. i don't have any idea why or how is this happening. i am running the project in eclipse, i have cleaned tomcat, closed eclipse and restarted it. but the result is the same.


can anyone tell me why is this happening. i hope i was able to explain the problem clearly....

Thanks
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

You probably have some form of authentication set up which requires users to login first. If you make a direct request without being logged in you probably get the login page as well. When logging in with a browser it usually does the work for you, storing the session ID in a cookie. With Java code it's a bit harder, but Apache's HttpClient can help you with that. You still need to go to the site twice - once to login and once to get the file. But the HttpClient will remember the cookie for you, so the second request will contain the information about being logged in.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
Actually i will be accessing the page from the inside of the application only, i.e. when the user has logged in. its only for testing that i am using a separate class file. so, the thing is that after user uploads the file, i want to read the file to process it, so just for testing, i am just reading the file and printing it on console. but this is where the problem comes, when i put the url which i am getting in the read function, the browser shows the correct contents, but when i read it, it shows the login page content.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!