弱问:在JSP或HTML里如何调用JAVASCRIPT函数? 上面的可以写在onclick="javascript:alert("提示");" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以将alert写在一个函数中,然后再body中调用.如:<script>function toalert(){alert("here the context");}</script>然后在body中写toalert();就可以了。 我有一个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> </td> </tr> </table> </form> </body> </html> 应该这样写:out.println("<Script language='javascript'>"); out.println("alert('对不起!密码或用户名不正确!')"); out.println("location='../index.jsp'"); out.println("</script>"); <c:if test> 如何判断两个类似否相等? 用struts+ejb是怎么来做项目的? 【探讨】关于延迟加载的问题的探讨 tomcat 后出现了要求输入用户名和密码的问题 怎么获得一个字符串的编码字符串 在LOGJ4配置打印日志的时候,不想把JSF里的内容打印出来,该怎么办? classes12.jar具体是做什么用的? servlet同时传俩个值怎么传 看看这段代码:建立数据库连接的javabeans,哪里错了????????? 我的JSP为什么找不到JDBC-ODBC驱动程序? 为什么我运行html时会出现一个帮助窗口 本地是好的,可到网上却出了问题(关于二级域名解析的问题)
如:
<script>
function toalert()
{
alert("here the context");
}
</script>
然后在body中写toalert();就可以了。
下面是源文件,老烦各位大虾米在给看看!小弟先谢谢了!
<%@ 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> </td>
</tr>
</table>
</form>
</body>
</html>
out.println("alert('对不起!密码或用户名不正确!')");
out.println("location='../index.jsp'");
out.println("</script>");