<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="connn" scope="page" class="conn"/>
<%!
ResultSet rst=null;
String username="";
String password="";
String sql="";
%>
<%
username=request.getParameter("UID");
password=request.getParameter("PWD");
sql="select * from User where Uname='"+username;
sql+="'and Upassw='"+password+"'";
try{
rst=connn.executeQuery(sql);
if(!rst.next()){
%>
<jsp:forward page="login.jsp">
<jsp:param name="errmsg" value="错误的用户名与密码"/>
</jsp:forward>
<%
}
}catch(Exception ee){
System.out.println(ee.toString());
%>
<jsp:forward page="abc.jsp"/>
<% }
response.sendRedirect("kkk.jsp");
%>
CONN.JAVA:
import java.sql.*;
public class conn {
private String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //"oracle.jdbc.driver.OracleDriver";
private String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=DB"; //"jdbc:oracle:thin:@127.0.0.1:1521:oracle";
private String user = "sa";
private String password = ""; public void setDriverName(String newDriverName) {
driverName = newDriverName;
}
public String getDriverName() {
return driverName;
}
public void setUrl(String newUrl) {
url = newUrl;
}
public String getUrl() {
return url;
}
public void setUser(String newUser) {
user = newUser;
}
public String getUser() {
return user;
}
public void setPassword(String newPassword) {
password = newPassword;
}
public String getPassword() {
return password;
} public Connection getConnection() {
try {
Class.forName(driverName);
return DriverManager.getConnection(url, user, password);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
} public static void main(String[] args) {
try{
conn dcm = new conn ();
Connection conn = dcm.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from User");
}catch(Exception e){
e.printStackTrace();
}
}
}
出错信息如下::exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a type
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
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)
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="connn" scope="page" class="conn"/>
<%!
ResultSet rst=null;
String username="";
String password="";
String sql="";
%>
<%
username=request.getParameter("UID");
password=request.getParameter("PWD");
sql="select * from User where Uname='"+username;
sql+="'and Upassw='"+password+"'";
try{
rst=connn.executeQuery(sql);
if(!rst.next()){
%>
<jsp:forward page="login.jsp">
<jsp:param name="errmsg" value="错误的用户名与密码"/>
</jsp:forward>
<%
}
}catch(Exception ee){
System.out.println(ee.toString());
%>
<jsp:forward page="abc.jsp"/>
<% }
response.sendRedirect("kkk.jsp");
%>
CONN.JAVA:
import java.sql.*;
public class conn {
private String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //"oracle.jdbc.driver.OracleDriver";
private String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=DB"; //"jdbc:oracle:thin:@127.0.0.1:1521:oracle";
private String user = "sa";
private String password = ""; public void setDriverName(String newDriverName) {
driverName = newDriverName;
}
public String getDriverName() {
return driverName;
}
public void setUrl(String newUrl) {
url = newUrl;
}
public String getUrl() {
return url;
}
public void setUser(String newUser) {
user = newUser;
}
public String getUser() {
return user;
}
public void setPassword(String newPassword) {
password = newPassword;
}
public String getPassword() {
return password;
} public Connection getConnection() {
try {
Class.forName(driverName);
return DriverManager.getConnection(url, user, password);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
} public static void main(String[] args) {
try{
conn dcm = new conn ();
Connection conn = dcm.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from User");
}catch(Exception e){
e.printStackTrace();
}
}
}
出错信息如下::exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a typeAn error occurred at line: 3 in the jsp file: /usercheck.jsp
Generated servlet error:
conn cannot be resolved to a type
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
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)
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="connn" scope="page" class="conn"/>
<%!
ResultSet rst=null;
String username="";
String password="";
String sql="";
%>
<%
username=request.getParameter("UID");
password=request.getParameter("PWD");
sql="select * from User where Uname='"+username;
sql+="'and Upassw='"+password+"'";
try{
rst=connn.executeQuery(sql);
if(!rst.next()){
%>
<jsp:forward page="login.jsp">
<jsp:param name="errmsg" value="错误的用户名与密码"/>
</jsp:forward>
<%
}
}catch(Exception ee){
System.out.println(ee.toString());
%>
<jsp:forward page="abc.jsp"/>
<% }
response.sendRedirect("kkk.jsp");
%>这里的connn是Connection对象的Statement吗?好像不是也,怎么可以这样用?
<jsp:useBean id="connn" scope="page" class="conn"/>
有问题吧
private String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //"oracle.jdbc.driver.OracleDriver";
private String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=DB"; //"jdbc:oracle:thin:@127.0.0.1:1521:oracle";
private String user = "sa";
private String password = "";private Connnection conn;
private Statement st;
private ResultSet rs;
public conn()
{
}
public void setDriverName(String newDriverName) {
driverName = newDriverName;
}
public String getDriverName() {
return driverName;
}
public void setUrl(String newUrl) {
url = newUrl;
}
public String getUrl() {
return url;
}
public void setUser(String newUser) {
user = newUser;
}
public String getUser() {
return user;
}
public void setPassword(String newPassword) {
password = newPassword;
}
public String getPassword() {
return password;
} public void getConnection() {
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, user, password);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}public ResultSet executeQuery(String sql)
{
rs = st.executeQuery(sql);
return rs;}
rst=connn.executeQuery(sql);
替换为
Connection conn=connn.getConnection();
Statement stmt=conn.createStatement();
rst=stmt.executeQuery(sql);
public conn(){
st=getConnection().createStatment();
}rst=connn.executeQuery(sql);