Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Creating URL in java

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating URL in java

    I m linux user... Developing my project in Eclipse IDE. and the project structure folder is Merchant.com(my project name)-->WebContent-->pg(folder)-->index.html(file).

    My code is
    public class Url {
     
    	/**
    	 * @param args
    	 */
     
    		public static void main(String[] args) {
    	        try {
    	            //
    	            // Creating a url object by specifing each parameter separately, including
    	            // the protocol, hostname, port number, and the page name
    	            //
    	            URL url = new URL("http", "www.Merchant.com" , 80, "/pg/index.html");
     
    	            //URL url = new URL("http://Merchant.com/index.html");
    	            // We can also specify the address in a single line.
    	            //www.merchant.com/pg/index.html
     
    	            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
     
    	            String line;
    	            while ((line = reader.readLine()) != null) {
    	                System.out.println(line);
    	            }
     
    	            reader.close();
    	        } catch (MalformedURLException e) {
    	            e.printStackTrace();
    	        } catch (IOException e) {
    	            e.printStackTrace();
    	        }
     
    	}
     
    }

    I m run this project on tomcat server so that the folder structure is mycomputer-->usr-->shear-->Apachetomcat-->webapps-->MyProject(created manually by me)-->Merchant.com so my question is where do i put index.html? Am i missing something?

    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Creating URL in java

    where do i put index.html
    Is this a question about how to configure a server?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating URL in java

    yes, this is about folder structure of tomcat server so that i can invoke index.html from my java application(in which we have created url). Currently we are getting error of "page not found" when we call the created url.

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating URL in java

    Should I upload index.html on web? Is this the solution of my issue?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Creating URL in java

    I don't know how to configure your server. One idea would be to put a different index.html page in all the possible folders and see which one is returned to the client's browser. When one is returned, you will know which folder it came from.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating URL in java

    I put index.html file in pg folder which is in my web address. pg folder is in Merchant.com. It didn't work.

  7. #7
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Creating URL in java

    you should create your pg folder inside WEB-INF directory that is beneath your web application and put index.html file in pg folder.

  8. #8
    Junior Member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating URL in java

    I have put index.html file in pg folder n pg folder in WEB-INF bt i m getting error 404. After move pg folder under WebContent all is working fine.

Similar Threads

  1. JAVA applet URL path (My computer and Web Host)
    By rajma in forum AWT / Java Swing
    Replies: 12
    Last Post: June 17th, 2013, 03:02 PM
  2. java servlet- want to redirect to custoem URL
    By abhivinay in forum Java Servlet
    Replies: 1
    Last Post: September 21st, 2012, 12:10 PM
  3. java.net.URL Access Exception
    By MistaWizurd in forum Java Networking
    Replies: 5
    Last Post: April 3rd, 2011, 03:18 AM
  4. Java - URL connection accessing Java Scrpit Function
    By virtual void in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 7th, 2010, 12:38 PM