上面的可以写在onclick="javascript:alert("提示");"

解决方案 »

  1.   

    可以将alert写在一个函数中,然后再body中调用.
    如:
    <script>
    function toalert()
    {
    alert("here the context");
    }
    </script>
    然后在body中写toalert();就可以了。
      

  2.   

    我有一个HTML的登陆页面,可以输入用户名和密码。然后有两个按钮,一个是登陆,一个是注册。登陆按钮将页面提交到一个JSP,在JSP中进行用户名称验证。如果验证成功,就<jsp:forward>到论坛首页,如果验证失败,就<jsp:forward>到登陆页面重登陆。我想实现的功能是,如果验证失败的话,能弹出一个对话框,alert("密码错误"),但是我不知道该怎么使用。我直接在JSP源文件里写<javascript alert("密码错误")>,不行
    下面是源文件,老烦各位大虾米在给看看!小弟先谢谢了!
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="err_techForumIndex.jsp" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

    <title>无标题文档</title>

    </head>

    <body>

    <form name="form1" method="post" action="" onSubmit="notice()">

    <%
      //得到用户登陆信息:
      String current_userName = request.getParameter("userName");
      String current_password = request.getParameter("password");
      //变量checkPassword用来存储从数据库里读出来的用户密码
      String checkPassword="";

      //通过建立数据库连接来验证用户登陆:



      //加载数据库驱动:
      String DBdriver="org.gjt.mm.mysql.Driver";
    try {
    //建立数据库驱动
    Class.forName(DBdriver).newInstance();
    }catch(java.lang.ClassNotFoundException e) {
     //没找到驱动异常
    System.err.println(e.getMessage());
    out.println(e.getMessage());
    }

      //建立连接:
    try {
    String url = "jdbc:mysql://localhost/poseidon?user=root&password=&useUnicode=true&characterEncoding=GBK";
        Connection conn= DriverManager.getConnection(url);

      //执行数据库查询语句并返回结果集
      String sql= "SELECT * FROM t_userinfo WHERE userName='"+current_userName+"' ";
      Statement stmt = conn.createStatement();
      ResultSet rst = stmt.executeQuery(sql);

      //通过查询用户在数据库的注册名得到用户的密码

      while(rst.next())
      {

      checkPassword=rst.getString("password");

      }



      if(checkPassword.equals(current_password))
      {
      if(!conn.isClosed())
      {
      rst.close();
      stmt.close();
      conn.close();
      }
      %>


    <jsp:forward page="techForumIndex.jsp">

    <jsp:param name="userName" value="<%=current_userName%>"/>

    <jsp:param name="password" value="<%=current_password%>"/>

    </jsp:forward>


    <%

    }
    else
    {
    if(!conn.isClosed())
      {
      rst.close();
      stmt.close();
      conn.close();
      }
      %>
                                我想在这里写一个意识密码错误的提示信息,利用alert()
    <jsp:forward page="techForumLogin.html">
     <jsp:param name="userName" value="<%=current_userName%>"/>
    </jsp:forward>

    <%
    }

      } catch(SQLException ex) {
    System.err.println(ex.getMessage());
    out.println(ex.getMessage());

    out.println(checkPassword);
     }
    %>
                <input type="hidden" name="hiddenField">
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">

    <tr>

    <td>&nbsp;</td>

    </tr>

      </table>

    </form>

    </body>

    </html>
      

  3.   

    应该这样写:out.println("<Script language='javascript'>");
       out.println("alert('对不起!密码或用户名不正确!')");
       out.println("location='../index.jsp'");
       out.println("</script>");