用JSP+tomcat4+SQLserver做一个登陆模块时的问题,急呀,在线等
我的程序包括两个部分
第一部分:login.html
这个部分是没问题的,我给它放在tomcat4的examples/jsp目录下
实现的是界面.
第二部分:verfiylogin.jsp
是用来和数据库实现连接的,源码如下:
<%@ page language= "java " contentType= "text/html; charset=UTF-8 "
pageEncoding= "UTF-8 "%>
<%@ page
import= "com.wxpn.tutorial.db.DB,com.wxpn.tutorial.db.ConnectionPool "%>
<%@ page
import= "java.sql.Connection,java.sql.Statement,java.sql.ResultSet,java.sql.SQLException "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<meta http-equiv= "Content-Language " content= "zh-cn ">
<title> 登录 </title>
</head>
<body>
<div align=center> <font color= "red "> <strong> <%//获取提交的用户名:
String strUserName = request.getParameter( "txtUserName ");
//获取提交的密码:
String strPassword = request.getParameter( "txtPassword ");
if((strUserName ==null)||(strUserName.equals( " "))||(strUserName.length()> 20)){
response.sendRedirect( "login.html ");
}
if((strPassword ==null)||(strPassword.equals( " "))||(strPassword.length()> 20)){
response.sendRedirect( "login.html ");
}
//创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
int nextMessageid = 0;
String relative_path = null;
//sql语句:
String sql = "select * from userInfo where username= ' "
+ strUserName + " ' and userpwd= ' " + strPassword + " ' ";
//创建数据记录集对象:
stmt = conn.createStatement();
//执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
//如果记录集为非空,表明有相匹配的用户名和密码,登录成功:
if (rs.next()) {
//登录成功时,把strUserName设成session变量UserName
session.setAttribute( "UserName ",strUserName);
out.println( "登录成功! ");
} else {
//否则(记录集为空),表明失败:
out.println( "登录失败! ");
}
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接,释放数据库资源:
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
%> </strong> </font> </div>
</body>
</html>
问提是当我运行http://localhost:8080/examples/jsp/login.html
时,在其中输入用户名和密码时,就出现如下错误:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /jsp/verifylogin.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\tomcat4\apache-tomcat-4.1.34\work\Standalone\localhost\examples\jsp\verifylogin_jsp.java:7: package com.wxpn.tutorial.db does not exist
import com.wxpn.tutorial.db.DB;
^
C:\tomcat4\apache-tomcat-4.1.34\work\Standalone\localhost\examples\jsp\verifylogin_jsp.java:8: package com.wxpn.tutorial.db does not exist
import com.wxpn.tutorial.db.ConnectionPool;
^
C:\tomcat4\apache-tomcat-4.1.34\work\Standalone\localhost\examples\jsp\verifylogin_jsp.java:59: cannot resolve symbol
symbol : class ConnectionPool
location: class org.apache.jsp.verifylogin_jsp
ConnectionPool connPool = DB.getConnPool();
^
An error occurred at line: 13 in the jsp file: /jsp/verifylogin.jsp
Generated servlet error:
C:\tomcat4\apache-tomcat-4.1.34\work\Standalone\localhost\examples\jsp\verifylogin_jsp.java:59: cannot resolve symbol
symbol : variable DB
location: class org.apache.jsp.verifylogin_jsp
ConnectionPool connPool = DB.getConnPool();
^
4 errors
我也知道错误是出在:DB 和 ConnectionPool上
而且DB.java和ConnectionPool.java我也有,问题是这两个文件的路径应放在tomcat4的路径是哪里,且放的是.java文件还是.class文件,急呀,求高手帮忙,要源码的话(DB.java和ConnectionPool.java)跟我说一声,分不够在给
[解决办法]
包没有找到.
把DB.java和ConnectionPool.java这两个文件编译好.
将它们的class文件名到WEB-INF\classes下.
就可以了.
最后classes下的目录应该是
classes\com\wxpn\tutorial\db\*.class
[解决办法]
你jar包什么的都没引入吧
com.wxpn.tutorial.db这个包下的类都没有找到.就是你没把jar包引进来
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html