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

FrameSet and error.jsp

Hideki Mae

Joined: Oct 19, 2004
Posts: 14
To all:
I have a web project using FrameSet. If an error occurs I want it to go to an error page (error.jsp). When an error does occur it does show the error page correctly. However, since I use FrameSets, the error page is posted on a targeted frame and not on the entire web page. Is there a way to make the browser post the error page in the whole browser?
In my servlet I tried reponse.sendRedirect() and forward(). I also tried creating another servlet for the error page and calling the servlet. None of it worked.
Thanks in advance for any help you can give me.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

None of it worked.

That's because the server-side code is completely clueless regarding the client-side windowing structure. Once a request is targetted to a specific window/frame/iframe there's not a thing you can do on the server to change where the response will be sent.

One thing you can do is to put Javascript in your error page to detect when the page is not being displayed in the top window and to redirect to the top window (known as a 'frame buster'). Problem with this approach is that, since it is a redirect, you lose any info in request-level scoped variables (which includes all the great error info that the container put there for you). So you need to find a way to propogate any error info that you want passed along to the redirect.

This is one of the reasons that framesets are universally loathed by web app authors. I never use them.

However, I do use iframes which exhibit the same behavior, so I need to deal with the situation as described above.
[ October 19, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Hideki Mae

Joined: Oct 19, 2004
Posts: 14
Thank you. The FrameBuster script worked. I modified it a little so I can pass arguments. Within my error.jsp code I put the frame buster script:
String lsapplication = (String)session.getAttribute("appname");
String lsErrMsg = (String)session.getAttribute("ErrMsg");
String lspreviouspage = (String)session.getAttribute("currentPage");

if (top.frames.length!=0){
top.location="/dwm/error.jsp?ErrMsg=" + "<%=lsErrMsg%>" + "&appname=" + "<%=lsapplication%>" + "¤tPage=" + "<%=lspreviouspage%>" ;

---bunch of other error.jsp code ---
lsapplication = request.getParameter("appname");
lsErrMsg = request.getParameter("ErrMsg");
lspreviouspage = request.getParameter("currentPage");

This way I can get the application name the previous page so I can put a button to go back to the previous application. For some reason I could not get the ErrMsg to come out. But I think that's relatively easy to fix.

Once again thank you.
I agree. Here's the link:
subject: FrameSet and error.jsp
It's not a secret anymore!