File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet and Frame Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet and Frame Problem" Watch "Servlet and Frame Problem" New topic

Servlet and Frame Problem

Mike Br

Joined: Nov 22, 2001
Posts: 20
Hiya, can anyone help. I have two frames on my page, a JSP page on the bottom and a Flash Movie on the top which posts data into a servlet. The servlet receives the data fine. I then use a forward statement in the servlet to pass the recived data into the JSP page (on the bottom frame). Problem is, the servlet output loads the JSP page into my top frame (over the Flash Movie). How can I tell the servlet to post to the bottom frame (where the JSP page is sitting waiting!!). Is this a javascript issue??
Any help much appreciated.
Napa Sreedhar
Ranch Hand

Joined: Jan 29, 2002
Posts: 62
Did you try posting the name of the bottom frame to the servlet.
I think that would help
Barron Greig

Joined: Jan 26, 2002
Posts: 8
I don't think there is a way of passing frame info directly to the HttpServletResponse. You do have to use a bit of Javascript. I wrote a support method for loading into a frame from servlet code. It's used something like
reloadFrame(response, "/myapp/Target.jsp");
In my code, the frame MUST have been given the same name as the jsp file without extension. For the above example, the frame could have been declared something like
<IFRAME name="Target" SRC="/myapp/Target.jsp"
The method itself:
protected void reloadFrame(HttpServletResponse response,
String frameURL)
throws IOException {
ServletOutputStream out = response.getOutputStream();
String frameName = (new File(frameURL)).getName();
StringTokenizer stok = new StringTokenizer(frameName, ".");
frameName = stok.nextToken();
out.println("<SCRIPT LANGUAGE=\"JavaScript\">");
out.println("frs = top.frames");
out.println("for (i = 0;i < frs.length;i++) {");
out.println(" if (frs[i].name == \"" + frameName + "\") {");
out.println(" top.frames[i].location.href=\"" + frameURL + "\"");
out.println(" break");
out.println(" }");
out.println("// -->");
Mike Br

Joined: Nov 22, 2001
Posts: 20
Thanks for your help guys, I'll try out that code and get back.
Thanks again,
I agree. Here's the link:
subject: Servlet and Frame Problem
It's not a secret anymore!