MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » JSP中嵌入JavaScript,该如何解决

JSP中嵌入JavaScript,该如何解决

www.MyException.Cn  网友分享于:2013-03-13  浏览:25次
JSP中嵌入JavaScript
<%@page import="javax.naming.spi.DirStateFactory.Result" import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=gb2312"
  pageEncoding="gb2312" %>
<!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>Insert title here</title>
</head>
<body>
<%
try{
//获取账号密码
String name=request.getParameter("text1");
String pwd =request.getParameter("pwd1");
//连接数据库
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=student";
String username="sa";
String userpwd="sa";
Connection conn=DriverManager.getConnection(url, username, userpwd);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from Table_1 where account='"+name+"'";

//String sql="select * from Table_1 ";

ResultSet rs=stmt.executeQuery(sql);
rs.first();

String s =(rs.getString("pwd")).trim();

//判断账号密码
if(pwd.equals(s)){
response.sendRedirect("welcome.jsp");
}else{
//response.sendRedirect("login.jsp");
%>
<script type="text/javascript">
 
alert("账号或密码错误!");

</Script>
<% 




else判断这一块,怎么才可以让他弹出警告对话框后返回到原来的登陆页面?

如果用response.sendRedirect()跳转 它不弹出来了。。








------解决方案--------------------
我QQ644486560
------解决方案--------------------
探讨
<%@page import="javax.naming.spi.DirStateFactory.Result" import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312" %>
<!DOCTYPE html PUBLIC "-/……

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有