how to create a popup message

i wanna have a popup message to inform the user that a particular action has been done successfully and redirect them to another page.

but the popup message doesnt appear when i apply the following codes.

// more codes

try{

Ps = Con.prepareStatement(sSQL);

Ps.executeUpdate();

System.out.println(sSQL);

Con.close();

}

catch (Exception e) {

System.err.print("Jdbc.Query(): " + e.getMessage());

}

output.println("<script language = javascript>");

output.println("alert(Added successfully);");

output.println("<script>");

String url = response.encodeRedirectURL("http://localhost:8080/....");

response.sendRedirect(url);

what's my mistake?

[759 byte] By [kacheeka] at [2007-10-2 18:24:27]
# 1
output.println("<script type=\"text/javascript\">");output.println("alert(Added successfully);");output.println("</script>");
matlasa at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
>output.println("<script type=\"text/javascript\">");>output.println("alert(Added successfully);");>output.println("</script>"); if tried that and the popup message doesnt appear too...
kacheeka at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
can you post the actual HTML portion of the response that write this javascript section?I would assume it should look like:<script type="text/javascript">alert("popup here");</script>
matlasa at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

here's the codes

String author = request.getParameter("txtAuthor");

String title = request.getParameter("txtTitle");

String art = request.getParameter("txtArt");

String desc = request.getParameter("txtDesc");

String status = request.getParameter("txtStatus");

String pdate = request.getParameter("txtDate");

String ptime = request.getParameter("txtTime");

String sSQL = "insert into tblArticle(Author, Title, Article, Description, Status, PDate, PTime) "

+ "values('"+author+"', '"+title+"', '"+art+"', '"+desc+"', '"+status+"', #"+pdate+"#, #"+ptime+"#)";

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch (Exception e) {

System.err.print("Jdbc.Open(): " + e.getMessage());

}

try{

Con = DriverManager.getConnection("jdbc:odbc:" + sDB, sUsr, Pwd);

}

catch (Exception e) {

System.err.print("Jdbc.Open(): " + e.getMessage());

System.out.println("Errorr!!!");

}

try{

Ps = Con.prepareStatement(sSQL);

Ps.executeUpdate();

System.out.println(sSQL);

Con.close();

}

catch (Exception e) {

System.err.print("Jdbc.Query(): " + e.getMessage());

}

output.println("<script type=\"text/javascript\">");

output.println("alert(Added successfully);");

output.println("</script>");

String url = response.encodeRedirectURL("http://localhost:8080/...");

response.sendRedirect(url);

kacheeka at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
You have to create a javascript redirect and place it right after the alert box code.window.location='page.jsp';Unless I'm mistaken, Your current code executes on the server side prior to the alert being written to the client.
SteveVaya at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

> You have to create a javascript redirect and place it

> right after the alert box code.

>

> window.location='page.jsp';

>

> Unless I'm mistaken, Your current code executes on

> the server side prior to the alert being written to

> the client.

If they post the response HTML you would be able to tell.

matlasa at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
SteveVay, u r rite. my codes execute on the server side n i wanna alert the user whose at the client side. how can i apply the code?
kacheeka at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

The response HTML will be whatever page he's redirecting to. The block of javascript code will never be used by the clients browser.

All server side code will be parsed and process before the page gets to the client. While the OP's code will write javascript into the response, it also overwrites it by redirecting to another page in the response.

An easy solution would be to put the javascript on the page that is redirected to, if this suits the requirements of the app. It's also a good idea to not rely on javascript as a means of moving the user through the application, but that's another topic. :)

SteveVaya at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

> SteveVay, u r rite. my codes execute on the server

> side n i wanna alert the user whose at the client

> side.

>

> how can i apply the code?

I didn't test this, but it's similar to the following. Note that I commented out the two last java lines. See my previous post though, I think you would be better off letting the server handle the forwarding and just put the alert on the destination page.

output.println("<script type=\"text/javascript\">");

output.println("alert(Added successfully);");

output.println("window.location='yourpage.jsp';");

output.println("</script>");

//String url = response.encodeRedirectURL("http://localhost:8080/...");

//response.sendRedirect(url);

SteveVaya at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
after inserting the output.println(.....) codes, the redirect page doesnt appear at all and surprisingly, there's no error message.
kacheeka at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

> after inserting the output.println(.....) codes, the

> redirect page doesnt appear at all and surprisingly,

> there's no error message.

I was able to get the code to run. I noted that there's a syntax error in your alert code - it's missing quotes around the output string.

Here's what the final javascript output would look like without being wrapped in java code...

<script type="text/javascript">

alert('Added successfully');

window.location='yourpage.jsp';

</script>

SteveVaya at 2007-7-13 19:45:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...