?
Solved

Detecting Frame with JSP

Posted on 2004-11-15
7
Medium Priority
?
290 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:mnphan
7 Comments
 
LVL 7

Expert Comment

by:lhankins
ID: 12588724
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
 

Author Comment

by:mnphan
ID: 12589049
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
 
LVL 28

Accepted Solution

by:
rrz earned 1000 total points
ID: 12589765
> 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mnphan
ID: 12589876
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
 
LVL 28

Expert Comment

by:rrz
ID: 12590202
>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
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 12592907
mnphan - with pure jsp you can not "bust" a frame. It is _just_ a way how a browser displays you html page.

0
 

Author Comment

by:mnphan
ID: 12606631
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question