• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create URL in java  RSS feed

 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone

I have created a URL "http://www.testmerchant.com/index.html" using java. When i try to invoke it, it didn't. I am trying to create index.html file on that location. Here is my code



I am confused why it didn't invoke when i run this code?

Thanks
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per your code, it is trying to read contents of index.html file from http://www.testmerchant.com. Sorry but you query is not clear. What exactly are you trying to achieve with this code?
 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actully, I have index.html in my project named testmerchant.com.I am ecllipse user n run this project on tomcat server. When i edit address by "http://localhost:8080/testmerchant.com/index.html" it run n show me the code but when i try this with "http://www.testmerchant.com/index.html" gives me IO exception FileNotFound. I created new Url www.testmerchant.com/index.html than why error occured?
 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i solve this?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a valid URL? testmerchant.com doss not seem to exist, so it's no surprise that an exception occurs if that's what you're actually using.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, when I run your code replacing http://www.testmerchant.com/index.html with http://www.google.com it works. You can only access your application on url where it is deployed to. If you have only deployed it to localhost then that is where you will see it.
 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf, i m trying to create this URL & trying to access index.html from this URl. I m new to this section of java. I googled it bt didn't help me more. Can i create a new URL using java?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have a basic misunderstanding. A Java URL object can be used to access a URL on a network, provided of course that the computer where the Java code is running can actually reach that URL.

You can create a Java URL object, but that doesn't allow you to access a URL (web address) which you don't have access to. It won't magically "create" that web address in any way. If you don't have access to it through your browser then you won't have access to it through your Java code either.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, let's be precise about wording: you can create java.net.URL objects with just about any String parameter (see the javadocs of the URL class if you're interested in the details) - as your code does. But just because you can create an URL object does not mean that the actual URL is valid - constructing a java.net.URL object is not the same as creating an actual URL that does not exist. So given that the URL "http://www.testmerchant.com/index.html" does not exist, I'm not sure why you're surprised that an exception occurs.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arpita,

You seem to have a web app deployed locally (as in one of your posts you have mentioned localhost) and probably you are trying to access the index.html file from there. Could you please tell us the directory structure of your web app, this might help us to figure out what url your java app should point to access the index.html file.
 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik,

Directry structure is

TestMerchant-->WebContent-->index.html.

I am a linux user.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your local system, right? and the following

http://localhost:8080/testmerchant.com/index.html

is already working. But to access www.testmerchant.com/index.html , you need to host your app through some service providers like godady or some other. Because your application is hosted locally not globally. Hosting an application in local machine does not mean that you can access through www.
 
arpita sabat
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for all the helpers.
 
Swastik Dey
Rancher
Posts: 1812
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome. We are always here to help you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!