日期:2014-05-19  浏览次数:21118 次

jsp登陆页面密码错误时,弹窗提示功能。
想在密码错误时,弹出一个提示窗口,即在下面代码注释的地方,不知道怎么调用js里的函数。。。。。。









<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'logincl.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->




<script type="text/javascript">

function alert()
{
window.alert("用户名或密码错误!");
}
</script>
 

 </head>
  
  <body>
<%
  String u=request.getParameter("username");
  String p=request.getParameter("passwd");
  if(u.equals("tracy")&&p.equals("000000"))
  {
  response.sendRedirect("welcome.jsp");
  }
  else 
  {
  //////////////////////////想在这里给出一个弹窗,就是调用alert(),不知怎么调,求助
   
  response.sendRedirect("login.jsp");
  }
%>  
   


  </body>
</html>


------解决方案--------------------
<%
String u=request.getParameter("username");
String p=request.getParameter("passwd");
if(u.equals("tracy")&&p.equals("000000"))
{
response.sendRedirect("welcome.jsp");
}
else
{
//////////////////////////想在这里给出一个弹窗,就是调用alert(),不知怎么调,求助

response.sendRedirect("login.jsp");
}
%>
你都跳走了,彈出來還有意思么?看得到么?
如果要用,直接 response.getWriter().write("<script > alert();</script>");
------解决方案--------------------
request.setAttribute("login", "fail");
response.sendRedirect("login.jsp");
------------------
js这个加个判断
<%
if(request.getAttribute("login").equals("fail")){

%>
<script>
function alert()
{
window.alert("用户名或密码错误!");
}
</script>

<%
}
%>
------解决方案--------------------
response.sendRedirect("login.jsp");
你不能用这个~!
------解决方案--------------------
同crlystaldong看法

------解决方案--------------------
探讨
ajax

------解决方案--------------------
同一个线程中,response不能两次响应客户端