• Post Reply Bookmark Topic Watch Topic
  • New Topic

closing window using jsp  RSS feed

 
charles mcghee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have created an application with a number of jsp's. i am using a controlling jsp to handle page ordering and linking to my server-side java code. i want to be able to close the browser window from this controlling jsp. unforunately this jsp is non-visible and has on buttons for me to attach a parent.window.close() to.
is there any piece of java code that i can put in my jspDestroy() method to close the browser .
thanks in advance
charles
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are misunderstanding how JSP works. Each JSP file is compiled to a servlet and runs on the server. The job of a JSP is to generate some text to send to the browser. This text may include HTML, JavaScript or whatever, but that generated text is just sent to the browser. It's up to the browser to decide what to do with the text sent from the server.
A JSP which does not produce something to be sent to the browser is not really a JSP, it's just a funny and cumbersome way of writing a Java class to run on the server. jspDestroy is only called when the compiled JSP servlet is removed from the server, which is likely to be after it has been run hundreds of times. It has nothing to do with the generation of pages, and even less to do with browser windows.
To close a browser window you need to run some JavaScript which has already been sent from the server.
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charles,
As Frank has suggested, it is not possible to close a window through a JSP.JSP is only a server-side rendering language/script, which gives HTML code as an output for the client browser to interpret.
However, you may prepare a response, which contains JavaScript commands, to close the Browser Window.The Browser would interpret this JavaScript command to close its window.
This is one of the many ways of doing it

Hope this helps,
Regards,
------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep,
One small doubt. Why are you using "out.print....()" method inside jsp. We can just write html and javascript as it is. No need to wrap them around out.printS().
THis is the PRIMARY advantage of using jsp over servlets. More htmls less java for jsp. More Java less (no) html for servlets.
Don't you think so?
regds
maha anna
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sandeep,
Almost everything you have between <% %> is unnecessary. Everything except "// Do whatever your JSP/Servlet wants" could just be put straight into the JSP without being inside <% %>.
Also, a JSPWriter out object is implicitly provided, there is no need to construct one (if you need to use it).
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi maha anna and Andrew Shafer,
You are both correct.I was first thinking of writing a JSP code then thought it would be more appropriate to demostrate with a Servlet, as it suits the following explanation:

However, you may prepare a response, which contains JavaScript commands, to close the Browser Window.

<% %> was an errata in the code, which I had missed to remove
I would request the "Friendly Bartenders" to edit the typos like above in the posts, in case they find it.

Hope this helps,
Regards,
------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep,
That's ok. If we edit your post and remove <% %> then the following posts may confuse the readers. Otherwise we have to edit your post and remove the following posts.
I would like to leave the thread as it is since the discussion flow is more natural.
regds
maha anna
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Regards,

------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!