MyEclipse编写JSP,连接数据库SqlServer2008 失败 5
<%@pagelanguage="java"import="java.util.*,java.sql.*,"pageEncoding="gb2312"%><%String...
<%@ page language="java" import="java.util.*,java.sql.*," 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">
-->
</head>
<body>
<%
String u=request.getParameter("username");
String p=request.getParameter("passwd");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=wen","wen","qwe123");
Statement sm=ct.createStatement();
ResultSet rs=sm.executeQuery("select passwd from users where username='"+u+"'");
if(rs.next())
{
if(rs.getString(1).equals(p)){
response.sendRedirect("wel.jsp?user="+u);
}else{
response.sendRedirect("login.jsp?errNo=1");
}
}else{
response.sendRedirect("login.jsp?errNo=2");
}
%>
</body>
</html> 展开
<%
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">
-->
</head>
<body>
<%
String u=request.getParameter("username");
String p=request.getParameter("passwd");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=wen","wen","qwe123");
Statement sm=ct.createStatement();
ResultSet rs=sm.executeQuery("select passwd from users where username='"+u+"'");
if(rs.next())
{
if(rs.getString(1).equals(p)){
response.sendRedirect("wel.jsp?user="+u);
}else{
response.sendRedirect("login.jsp?errNo=1");
}
}else{
response.sendRedirect("login.jsp?errNo=2");
}
%>
</body>
</html> 展开
2014-11-23
展开全部
代码说的很清楚吗,说明不能组装为jsp,然后错误行轿迹脊为8,接着说import错误,我记得util包一般时候是不用写的。。。唉,等我有空开软件看看。。。你这个jsp前面都是自动生成的吧,除了那个import是吧?后面的代码我就不看了,,,
次奥,你的页面怎州配么全是java代码啊,你的html代码呢,另闭渗外连接数据库不是后台的么,你怎么放到页面来了,这样代码全泄漏了,从来没人把数据库的dbconnection放到页面来,你真奇才。。。
你的web.XML怎么配置的哦?
次奥,你的页面怎州配么全是java代码啊,你的html代码呢,另闭渗外连接数据库不是后台的么,你怎么放到页面来了,这样代码全泄漏了,从来没人把数据库的dbconnection放到页面来,你真奇才。。。
你的web.XML怎么配置的哦?
追问
学了半年多Java, 最近学了servlet,JSP刚开始着手,Java SE 数据库操作顺畅,MyEclipse开发JSP却连接不上,因为是新手所以不知道怎么办,这个真的不知道怎办办了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询