• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inputstream reading wrong file when a url is passed.

 
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic