try
{
int num=0;
String user=request.getParameter("username");
String password=request.getParameter("password");
String query="select * from registeredUsers where (userid=? or emailid=?) and (password=?)";
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql:///kush_cabs","root","");
PreparedStatement pst=con.prepareStatement(query);
pst.setString(1,user);
pst.setString(2,user);
pst.setString(3,password);
ResultSet rs=pst.executeQuery();
if(rs.next())
num=rs.getRow();
if(num>=1)
{
String name=rs.getString(2);
h1.setAttribute("username",name);
h1.setAttribute("userid",user);
response.sendRedirect("UserMain.jsp");
}
else
{
out.println("<script='text/javascript'>");
out.println("alert('please enter the valid username');");
out.println("</script>");
}
}
catch(Exception ae)
{
out.println(ae.getMessage());
}
不显示警告框。该消息显示在"alert('请输入有效用户名');"
您缺少type属性。使用out.println("<script type='text/javascript'>");