Detecting Frame with JSP

Hi,

I am running a JSP Server with Tomcat 4.1
How can I detect a page if it is in a frame (or frameset).

This question should be easy if we using JavaScript code:

if (self != top)
    alert('In a frame');
else
    alert('Not in a frame');

but I need a pure JSP code, not javascript !

Please help, Thanks so much.
mnphanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lhankinsCommented:
You can use JS from JSP.

A JSP is implicitly compiled into a Servlet by the servlet container.   A Servlet will service a request and return back an HTML response stream (which can include CSS, JS, etc).

So basically  you have :

    JSP -> Servlet -> HTML Document

0
mnphanAuthor Commented:
Thanks lhankins,

You're right,

I even finish my JSP program in that way. It worked well except it turns out to another problem.

When I detect a page in a frame using a javascript  and depending on this page if it is in a frame or not I then redirect it to another page, either frame.jsp or no_frame.jsp

if (self != top)
   window.location.replace('/no_frame.jsp');
else
    window.location.replace('/have_frame.jsp');

but  when I redirect the page using JavaScript, I lost all the informations (error message, log-in status...) in that section.

I thought, it will be different if I can detect a page in a frame directly using JSP code and then using <jsp:forward page="no/have_frame.jsp"> which I still keep all information  in that section.

mnphan

0
rrzCommented:
> I lost all the informations (error message, log-in status...) in that section.
Where are you storing that data ?
Could you use session object ?  ( session.setAttribute(String,Object); )
Could you use query string ? Something like
window.location.replace('/no_frame.jsp?p1=1&p2=2');    
rrz

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

mnphanAuthor Commented:
Could you use session object ?  ( session.setAttribute(String,Object); )
Yes. I using some thing like:
<jsp:useBean id = "id1" class="ErrorMsg" scope="session"/>
When I redirect a page using JavaScript window.location.replace('/no_frame.jsp'); I will lost all information in this session.

> window.location.replace('/no_frame.jsp?p1=1&p2=2');
It works but I really don't like this because p1 could be contain some values that I don't want to display to user via URL address.

mnphan




0
rrzCommented:
>When I redirect a page using JavaScript window.location.replace('/no_frame.jsp'); I will lost all information in this session.
Why is that  ?
Did you  use
sessionId=<%=session.getId()%>  
to test ?
0
Oliver_DornaufCommented:
mnphan - with pure jsp you can not "bust" a frame. It is _just_ a way how a browser displays you html page.

0
mnphanAuthor Commented:
Thank you you all,
and sorry for this late post, as I was unable to post a message at home, I don't know why my PC couldn't see a text box where to type this message.

rrz, you're right again, when I redirected a page using JavaScript window.location.replace('/no_frame.jsp'); it does not lose any information in that session, every thing was still there, I was wrong because before redirect the page I did get those info and clear them.

My problem is now solved, I close this topic and give the credit for rrz, who pointed out my error.

Thanks all
PS. However, if some one has any idea to detect a frame using with pure JSP, please post. I still believe that JSP can do it without any help from other language !
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.