mnphan
asked on
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.
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.
ASKER
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.j sp');
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
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('/
else
window.location.replace('/
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you use session object ? ( session.setAttribute(Strin g,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.j sp'); I will lost all information in this session.
> window.location.replace('/ no_frame.j sp?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
Yes. I using some thing like:
<jsp:useBean id = "id1" class="ErrorMsg" scope="session"/>
When I redirect a page using JavaScript window.location.replace('/
> window.location.replace('/
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
>When I redirect a page using JavaScript window.location.replace('/ no_frame.j sp'); I will lost all information in this session.
Why is that ?
Did you use
sessionId=<%=session.getId ()%>
to test ?
Why is that ?
Did you use
sessionId=<%=session.getId
to test ?
mnphan - with pure jsp you can not "bust" a frame. It is _just_ a way how a browser displays you html page.
ASKER
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.j sp'); 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 !
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('/
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 !
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