使用Dreamwer中的JSP进行网页制作,当从一个页面来取另一个页面的值时却出现了错误应该怎么办?
在本地计算机上安装了SQLServer2000,并且安装了JAVA与Dreamwer与Apache Tomcat,在Dreamwer中第一个页面是:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="logining.jsp">
<table width="244" border="0">
<tr>
<td width="56">用户名</td>
<td width="178">
<input name="username" type="text" id="username" maxlength="20"/>
</td>
</tr>
<tr>
<td>密码</td>
<td>
<input name="pwd" type="password" maxlength="15" />
</td>
</tr>
<tr >
<td colspan="2" align="center"><input type="submit" class="sub" value="登录"/>
<input type="submit" class="sub" value="注册"/></td>
</tr>
</table>
</form>
</body>
</html>
第二个页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*,com.microsoft.jdbc.sqlserver.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password= request.getParameter("pwd");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDiver");
DriverManager.registerDriver(new SQLServerDriver());
String url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=bookshop";
String user="sa";
String pwd="";
Connection conn=DriverManager.getConnection(url,user,pwd);
String sqlQue = "select count(*) from user where username=? and password=?";
PreparedStatement pst=conn.PreparedStatement(sqlQue);
pst.setString(1,username);
pst.setString(2,password);
ResultSet rs=pst.executeQuery();
rs.next();
int count = rs.getInt(1);
rs.close();
pst.close();
conn.close();
if (count <= 0 ) { //失败
%>
<meta http-equiv="refresh" content="1;url=login.jsp">
<%
}
else {
%>
<p>"某某小组偶登陆成功了"</p>
<%
}
%>
<p>你刚刚输入的用户名是:<%=username%></p>
<p>你刚刚输入的密码是:<%=pwd%></p>
</body>
</html>
第一个页面当然没有错,但是第二个页面始终出现一个错误:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /logining.jsp
Generated servlet error:
The method PreparedStatement(String) is undefined for the type Connection
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
.................
请大家帮我解决一下了啦!