Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

inputstream reading wrong file when a url is passed.

 
Ranch Hand
Posts: 590
6
jQuery Java
  • 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: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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: 590
6
jQuery Java
  • 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.

 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic