www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to set up form action

  1. #1
    Join Date
    Dec 2009
    Posts
    15

    Red face How to set up form action

    I've been developing a web app on a single computer and have been using http://localhost:8080/myServlet in my form action field.

    Now I'm trying to run my server on a remote machine and can get my web page to come up, but when I hit the Submit button, it tries to access the local host, not the host where the server resides. I'm sure that I can hard-code the name of the server instead of localhost, but what happens if the web app gets moved to a different server? I'd have to modify index.html to set the new name of the server.

    How can I setup the action property such that it will access myServlet no matter the name of the server that it resides on?

  2. #2
    Join Date
    Dec 2009
    Location
    Colorado
    Posts
    104
    You could do this with javascript. You could change the url (action) in the form tag or use javacript document.form1.submit();

    You could figure out which location the code is running on using javascript location object.

    var currentURL = window.location;
    alert ( currentURL.host ); // Displays 'www.example.com:80'

  3. #3
    Join Date
    Jan 2009
    Posts
    3,346
    As an alternative use relative paths (../page.htm, page1.html) instead of absolute paths (http://yourserver.domain/page.htm, http://yourserver.domain/folder/page1.html). Then you can change servers or domains to your hearts content without having to use javascript hacks.

  4. #4
    Join Date
    Dec 2009
    Posts
    15

    Thumbs up

    Quote Originally Posted by criterion9 View Post
    As an alternative use relative paths (../page.htm, page1.html) instead of absolute paths (http://yourserver.domain/page.htm, http://yourserver.domain/folder/page1.html). Then you can change servers or domains to your hearts content without having to use javascript hacks.
    That worked! Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles