how do i close the browser from a servlet ?

M

Max

is there a quick way to close the browser from a servlet ?

for the moment, when the user clicks on QUIT, I do a redirection to another
html page

Redirection redirection = new Redirection("/index.html");
return redirection;

How do i just close the browser, without any redirection ?.
thanks
 
W

Wendy S

Max said:
is there a quick way to close the browser from a servlet ?
for the moment, when the user clicks on QUIT, I do a redirection to another
html page
Redirection redirection = new Redirection("/index.html");
return redirection;
How do i just close the browser, without any redirection ?. thanks

If the client allows JavaScript, you can send them a page with
window.close();

Depending on their settings, they may get a warning saying that something is
trying to close the window.

You aren't closing the browser from the servlet though, just sending a bit
of JavaScript that gets executed on the client side.
 
M

Max

yeah, i thought about that solution but i don't want to use javascript.
there must be a way to close a window directly from a servlet, no ?
 
M

Max

close.html :
<html>
<body onLoad="window.close()">
</body>

Servlet :
Redirection redirection = new Redirection("/close.html");

this would work perfectly but then i need to add an html file to my webapp,
i don't want that ..
 
W

Wendy S

Max said:
close.html :
<html>
<body onLoad="window.close()">
</body>

Servlet :
Redirection redirection = new Redirection("/close.html");

this would work perfectly but then i need to add an html file to my webapp,
i don't want that ..

No you don't have to create a close.html file on your web server. It's been
a long while since I've messed with Servlets (everything is Struts and now
web services) but you can "write out" your response directly from the
Servlet.

Go back to your very first "Hello World" Servlet... wasn't it something
like:
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println("<html><body>Hello World!</body></html>" );
??
 
M

Max

hehe yes, could do that ... ;-)
Wendy S said:
No you don't have to create a close.html file on your web server. It's been
a long while since I've messed with Servlets (everything is Struts and now
web services) but you can "write out" your response directly from the
Servlet.

Go back to your very first "Hello World" Servlet... wasn't it something
like:
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println("<html><body>Hello World!</body></html>" );
??
 
G

Grant Wagner

You could do that, but if the window you are attempting to close wasn't opened
by JavaScript, or has history, the browser will either fail to close the window,
or prompt the user that the window is about to be closed, and request their
permission first.
 
J

Joona I Palaste

OMG, everybody is giving you the wrong answer. Just do System.exit(0); That
will close the web browser that the client is using. You don't even have to
send anything to the client's browser. Why should it? Its not like you are
trying to tell the browser to do anything. The servlet doesn't need to know
anything about javascript to close the browser. Good luck.

What the heck are you babbling about? Did you read any of the messages
which said that Servlets run ON THE SERVER SIDE? Calling System.exit(0)
would close the Servlet container - ON-THE-SERVER-SIDE. On the server -
bleeding - side. The client browser would not even notice it. All it
cares about is getting a HTTP feed from some connection.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"As a boy, I often dreamed of being a baseball, but now we must go forward, not
backward, upward, not forward, and always whirling, whirling towards freedom!"
- Kang
 
M

Miguel De Anda

Joona I Palaste said:
What the heck are you babbling about? Did you read any of the messages
which said that Servlets run ON THE SERVER SIDE? Calling System.exit(0)
would close the Servlet container - ON-THE-SERVER-SIDE. On the server -
bleeding - side. The client browser would not even notice it. All it
cares about is getting a HTTP feed from some connection.



Hello, sarcasm.
 
M

Miguel De Anda

Jonathan Oexner said:
"Miguel De Anda" <_sodamnmad_@_hotmail_._com_> wrote in message

Sir, this is USENET! Sarcasm and bad advice have no place here.

Well the guy has been told the solution a few times already. He just doesn't
want to do it way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,268
Messages
2,571,095
Members
48,773
Latest member
Kaybee

Latest Threads

Top