#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    7
    Rep Power
    0

    using servlet output


    Hi..
    I have an html page with two pages. The top page is static and has a few icons. The bottom page displays output from a servlet. It has two hidden elements in it. When I click the icon in the top page I want to refer the hidden elements in the bottom page,

    I am using javascript to refer the variables as follows.

    top.framename.elementname.value

    This is not working, however if i write the servlet output to a temporaray file and open this file in bottom frame then the same code is working perfectly. How can i use the elements in the servlet output without creating the temporary file.

    Thanks,
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Post the servlet code and all the html pages here please.
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Are all the pages coming from the same server? If you try to load the servlet frame from a different server you won't be able to access it with javascript (security reasons).
    -james
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    7
    Rep Power
    0

    sample code


    Hi..
    I am testing the following on a localmachine using the server provided by servlet developement kit. I have an html page which has two frames the code for this page is as follows

    ***************************************************
    Main Page

    <html>
    <frameset rows="35,*">
    <frame src="static1.html" name="static">
    <frame src="http://localhost:8080/servlet/TestServletOutput" name="dynamic">
    </html>

    *************************************************

    page static1.html is as follows

    *************************************************
    static1.html

    <html>
    <script language="javascript">
    function get_drill()
    {
    alert(top.dynamic.form_new.first.value);
    }
    </script>
    <input type=button value=click onclick=get_drill();>
    <input type=hidden name=first value="-1">
    </html>

    **************************************************

    the bottom frame contains the servlet..the servlet is as follows.

    *************************************************
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class TestServletOutput extends HttpServlet {

    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    {

    doPost(request,response);
    }

    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<br><head></head><br><body><br><form name=form_new><br><input type=text name=\"first\" value=\"xyz\"><br>");
    out.println("</form><br></body><br></html>");
    out.close();
    }
    }

    ***************************************************

    I have posted the entire code so that you guys can just copy it and test it. I get the error

    Runtime error, permission denied.

    Both of the files are coming from my local machine so why does it give permission denied.

    Thanks for all your replies,

    - yedaanna
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    When you are opening the main page, are you requesting it through the web server, or are you jusst double clicking on it in windows explorer? If you are double clicking on it, it will probably fail. Try opening up Internet Explorer and typing in the url with localhost and the port and see what it does.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    7
    Rep Power
    0

    worked on webserver


    Hi..
    the code i posted works perfectly on my companys web server, dont know what the problem is with the local machine.

    thanks

    yeda
  12. #7
  13. Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    49
    Rep Power
    14
    Javascript only allows you to act on pages that are part of the same domain. So, if your frameset is on www.xyz.com, you will not be able to control a frame located on www.abc.com.

    So, if you launch your frameset from http://localhost, eg http://localhost/index.htm, and poth frames within you frameset are located on the same server, eg. http://localhost/top.htm and http://localhost/bottom.htm, then you can have javascript acting from one frame to the other. If the pages are on different servers, eg. the bottom frame is on www.xyz.com, then you won't be able to use Javascipt on it.

    In short, if you don't launch your index /frameset page from http://localhost:8080, then it won't work

    regards,
    Elie

IMN logo majestic logo threadwatch logo seochat tools logo