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....
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.
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: