JSP编译失败的问题

thebesteric 2013-03-07 03:21:36
各位老师,小弟刚开始学JSP,在做一个用户验证的过程中,出现了一点问题,自己也找了问题,也没理清楚,所以到此请教,忘各位不吝赐教!

开发环境:
IDE:eclipse
TOMCAT:7.0
DB:SQL2000

问题描述:
在login登录后,进行loginCL.jsp的时候,进行报错,报错提示如下:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 16 in the jsp file: /WebContent/loginCL.jsp
UserBeanCL cannot be resolved to a type
13: String p = request.getParameter("password");
14:
15: //验证用户名和密码,调用UserBeanCL的checkUser方法
16: UserBeanCL ubcl = new UserBeanCL();
17:
18: if(ubcl.checkUser(u, p)){
19: //设置Session


An error occurred at line: 16 in the jsp file: /WebContent/loginCL.jsp
UserBeanCL cannot be resolved to a type
13: String p = request.getParameter("password");
14:
15: //验证用户名和密码,调用UserBeanCL的checkUser方法
16: UserBeanCL ubcl = new UserBeanCL();
17:
18: if(ubcl.checkUser(u, p)){
19: //设置Session

PS:我自己也分析了以下,应该不会是UserBeanCL.java出现的问题,是不是那些地方没有设置好?
导致jsp找不到这个类?


以下为涉及到的源码

===login.jsp===

<%@ 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>用户管理系统</title>
</head>
<body bgcolor="#CED3FF">
<center>
用户登录<br>
<hr>
<form action="loginCL.jsp" method="post">
用户名:<input type="text" name="username" ><br>
密  码:<input type="password" name="password" ><br>
<input type="submit" value="登录" >
<input type="reset" value="重置" >
</form>
</center>
</body>
</html>

===loginCL.jsp===

<%@ page language="java" import="java.util.*,java.sql.*,com.eric.model.*" 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>用户管理系统</title>
</head>
<body bgcolor="#CED3FF">
<%
//接收用户名和密码,完成对用户的验证
String u = request.getParameter("username");
String p = request.getParameter("password");

//验证用户名和密码,调用UserBeanCL的checkUser方法
UserBeanCL ubcl = new UserBeanCL();

if(ubcl.checkUser(u, p)){
//设置Session
HttpSession hs = request.getSession();
hs.setMaxInactiveInterval(60*3);
hs.setAttribute("username", u);
hs.setAttribute("password", p);

response.sendRedirect("welcome.jsp");
}else{
response.sendRedirect("login.jsp");
}

%>
</body>
</html>

===ConnDB.java===

//得到数据库的连接

package com.eric.model;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnDB {

private Connection ct = null;

public Connection getConn(){
try {
//1、加载驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//2、得到连接
ct = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=ericdb","sa","");
} catch (Exception e) {
e.printStackTrace();
}
return ct;
}
}

===UserBeanCL.java===

//这是一个处理类
//主要是封装对users表的各种业务逻辑操作
package com.eric.model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class UserBeanCL {

private Connection ct = null;
private Statement sm = null;
private ResultSet rs = null;

//验证用户是否合法
public boolean checkUser(String u,String p){
boolean flag = false;
try {
ct = new ConnDB().getConn();
//创建Statement
sm = ct.createStatement();
//查询
String usql = "select passwd from users where username='"+u+"'";
rs = sm.executeQuery(usql);

//根据结果进行判断
if(rs.next()){
//说明用户存在
if(rs.getString(1).equals(p)){
//合法用户
flag = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭打开的资源
this.closeDB();
}

return flag;
}

//关闭资源
public void closeDB(){
try {
if(rs!=null){
rs.close();
rs=null;
}
if(sm!=null){
sm.close();
sm=null;
}
if(ct!=null){
ct.close();
ct=null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
...全文
282 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdf_321 2013-04-19
  • 打赏
  • 举报
回复
楼主怎么搞定的 我也遇到类似问题了 求指教!
thebesteric 2013-03-07
  • 打赏
  • 举报
回复
引用 5 楼 wyx100 的回复:
回复于: 2013-03-07 15:34:39 UserBeanCL是你自己写的?如果是的话不能这样写吧,应该<jsp:useBean id=" ubcl" scope="page" class="UserBeanCL">,在jsp文件的前面,
这个文件加在什么地方,加上以后,显示红线,有错误 <jsp:useBean id=" ubcl" scope="page" class="UserBeanCL"> <%@ page language="java" import="java.util.*,java.sql.*,com.eric.model.*" 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> ...
wyx100 2013-03-07
  • 打赏
  • 举报
回复
回复于: 2013-03-07 15:34:39 UserBeanCL是你自己写的?如果是的话不能这样写吧,应该<jsp:useBean id=" ubcl" scope="page" class="UserBeanCL">,在jsp文件的前面,
yyw6637 2013-03-07
  • 打赏
  • 举报
回复
看看2楼的说法
thebesteric 2013-03-07
  • 打赏
  • 举报
回复
引用 1 楼 yyw6637 的回复:
UserBeanCL ubcl = new UserBeanCL(); 这一句不能被实例化,你导入其包了没
loginCL.jsp中增加了 <%@ page language="java" import="java.util.*,java.sql.*,com.eric.model.*" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> 这样应该算是导入了吧
微风飘过 2013-03-07
  • 打赏
  • 举报
回复
UserBeanCL是你自己写的?如果是的话不能这样写吧,应该<jsp:useBean id=" ubcl" scope="page" class="UserBeanCL">,在jsp文件的前面,
yyw6637 2013-03-07
  • 打赏
  • 举报
回复
UserBeanCL ubcl = new UserBeanCL(); 这一句不能被实例化,你导入其包了没

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧