| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1688 人关注过本帖
标题:JSP + Tomcat 5.5 + SQL Server 2000 出错,始终找不到原因,帮忙看一下
只看楼主 加入收藏
bigpeach
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
JSP + Tomcat 5.5 + SQL Server 2000 出错,始终找不到原因,帮忙看一下
首先是我的环境变量:

  classpath :.;D:\Java\jdk1.6.0_18\lib\tools.jar;D:\Java\jdk1.6.0_18\lib\dt.jar

  JAVA_HOME : D:\Java\jdk1.6.0_18

  Path : D:\Java\jdk1.6.0_18\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\80\Tools\BINN


我的Tomcat 路径是:C:\Program Files\Apache Software Foundation\Tomcat 5.5

我把整个代码包括Jsp和Java所有的文件都放在文件夹 Code 里;

Code的路径是 : C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myapp\Code

Code里除了有些JSP和html文件外还有三个文件夹:admin(里面放着JSP文件)、WEB-INF(此文件夹中有一个classes文件夹 ,classes文件夹中包括comm和 Information文件夹,这两个文件夹中放着java文件)和images(里面是图片)。


  我在浏览器地址栏中输入:http://localhost:9090/myapp/Code/index.jsp
出现错误:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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: 42 in the jsp file: /Code/admin/InfoComm.jsp
User cannot be resolved to a type
39: public String getName(String Userid)throws Exception
40: {
41:  try{
42: User o_user = new User();
43: o_user.setUserId(Userid);
44: if(o_user.getUser())
45:  {


An error occurred at line: 30 in the jsp file: /Code/left.jsp
Categories cannot be resolved to a type
27: //如果是管理员,则可以设置用户信息,如果是其他用户则可以更改自己的密码
28: // 定义用户对象
29: Vector v_Cate = new Vector();
30: Categories o_Cate = new Categories();
31: v_Cate = o_Cate.getMoreCategories();
32: for(int i=0;i <v_Cate.size();i++)
33: {

An error occurred at line: 34 in the jsp file: /Code/left.jsp
Categories cannot be resolved to a type
31: v_Cate = o_Cate.getMoreCategories();
32: for(int i=0;i <v_Cate.size();i++)
33: {
34: o_Cate = (Categories)v_Cate.elementAt(i);
35: %>
36: <tr> <td align="center"> <a href="infoList.jsp?cid= <%=o_Cate.getCateId()%>" target="main" style="text-decoration: none"> <%=o_Cate.getCateTitle()%> </a> </td> </tr>
37: <% }%>


Stacktrace:
org.apache.(DefaultErrorHandler.java:93)
org.apache.(ErrorDispatcher.java:330)
org.apache.(JDTCompiler.java:451)
org.apache.(Compiler.java:319)
org.apache.(Compiler.java:298)
org.apache.(Compiler.java:286)
org.apache.jasper.(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.28


下面我将把其中几个文件贴上来,大家帮忙分析一下到底是哪里的问题或错误,谢谢!
  
 
 
 


[ 本帖最后由 bigpeach 于 2010-2-11 22:28 编辑 ]
搜索更多相关主题的帖子: Server JSP SQL Tomcat 
2010-02-11 22:10
bigpeach
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-11
收藏
得分:0 
数据库的连接文件 DBOper.java (说明一下:这个文件原来是连的Oracle数据库,但我电脑配置太低,怕跑不起来,换成SQL Server 2000了,相应的语句也改了,不知有没有错误?):

package comm;

import java.sql.*;
import *;
import java.util.*;
import oracle.jdbc.*;  // 引用JDBC驱动包
import Information.*;

public class DBOper {
    private Connection conn = null;
    private Statement stmt = null;
    // 数据库连接
public void connectDB() throws Exception
{
String hostName      = "localhost";  // 主机名或者IP地址
        String portNumber    = "1433";//"1521";      // 端口号,默认为1521
        String databaseSID    = "oracledb";  // SID名称
//      String userName      = "devsys";    // 用户名
  //        String password      = "devsys";    // 用户密码
String userName      = "sa";    // 用户名
    String password      = "newsmanager";    // 用户密码

String url = "jdbc:microsoft:sqlserver://"+hostName+":"+portNumber+":"+databaseSID;
//String url = "jdbc:oracle:thin:@"+hostName+":"+portNumber+":"+databaseSID;  // 连接字符串
System.out.println(url);  // 打印连接字符串
try{
// 装载驱动程序
Class.forName("com.microsoft.JDBC.sqlserver.SQLServerDriver");
//Class.forName("oracle.jdbc.driver.OracleDriver");
// 建立连接
conn = DriverManager.getConnection(url,userName,password);
        }
        catch (Exception e){
// 如果有异常,则抛出错误
            System.out.println("=====Exception : DBOper connectDB() exception: " + e.getMessage());
        }
    }
// 获取数据库连接对象
public Connection getConnection() throws Exception
{
return conn;
}
// 执行查询,返回单一结果
    public ResultSet getResultSet(String sql) throws SQLException
    {
        try{
// 如果数据库没有连接,则连接数据库
if(conn==null)
connectDB();
        }
        catch (Exception e){
            throw new SQLException(e.getMessage());
        }
// 如果语句为空,则创建语句
if(stmt ==null)
        stmt =conn.createStatement();
// 执行查询,返回查询结果集
      return stmt.executeQuery(sql);
    }
// 添加、删除、更新操作
    public void DataUpdate(String sql) throws SQLException
    {
        try
        {
// 连接数据库
if(conn==null)
connectDB();
  // 创建语句
if(stmt ==null)
stmt =conn.createStatement();
  // 执行更新操作
          stmt.executeUpdate(sql);
        }
        catch (Exception e)
        {
            throw new SQLException(e.getMessage());
        }
}
    // 关闭
    public void close() throws SQLException
    {
// 设置自动提交
conn.setAutoCommit(true);
// 关闭语句,关闭连接
        if(stmt!=null) {stmt.close();stmt  =null;}
        if(conn!=null) {conn.close();conn  =null;}
    }
}
2010-02-11 22:11
bigpeach
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-11
收藏
得分:0 
错误信息中提到的那个页面InfoComm.jsp:

<%@page import="java.text.*,java.util.Date,java.util.*,java.lang.*,*,Information.*,comm.*"%>
<%!
public final int MaxPerPage = 20; //每页信息个数
public String IMG_SITE;
public String IMG_LABLE_F = " <P[space]align=center> <IMG[space]SRC=";
public String IMG_LABLE_L = "> </P> <p>";
public String strBG1="#FFFFFF";
public String strBG2="#FEEC85";
public String strbg;

//替换字符串中的字符
public static String replaceString(String origStr, String oldStr, String newStr) {
      if (origStr == null || origStr.length() == 0 || oldStr == null ||
          oldStr.length() == 0 || newStr == null) {
          return origStr;
      }
      StringBuffer buffer = new StringBuffer();
      // find the oldStr's place in origStr
      while (origStr.indexOf(oldStr) != -1) {
          int index = origStr.indexOf(oldStr);
  buffer.append(origStr.substring(0, index));
  buffer.append(newStr);
  origStr = origStr.substring(index+oldStr.length());
    }
      buffer.append(origStr);
      return buffer.toString();
  }
// 判断是否为新信息
boolean isNew(String adate)
{
Calendar c=Calendar.getInstance();
SimpleDateFormat thismonth = new SimpleDateFormat("yyyy-MM-dd");
c.add(Calendar.DATE, -3);
String slastday=thismonth.format(c.getTime());

if((adate) <=0) return true;
else return false;
}
public String getName(String Userid)throws Exception
{
  try{
User o_user = new User();
o_user.setUserId(Userid);
if(o_user.getUser())
  {
return o_user.getEmplName();
  }
  }catch(Exception e)
        {System.out.println(e.toString());}
  return "";
}
// 判断用户是否存在
public boolean IsUser(String userid,String passwd)throws Exception
{
try{
if(userid.length()==0 || passwd.length()==0)
return false;
else{
// 定义用户对象,设置其用户名和密码
User o_user = new User();
o_user.setUserId(userid);
o_user.setPassWord(passwd);
// 判断是否存在此用户信息,如果存在此用户则返回true
if(o_user.getUser())
{System.out.print("pppp");
return true;
}
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
// 判断用户类型
public int getType(String userid)throws Exception
{
try{
if(userid.length()==0)
return 0;
else{
// 定义用户对象,设置其用户名和密码
User o_user = new User();
o_user.setUserId(userid);
// 判断是否存在此用户信息,如果存在此用户则返回true
if(o_user.getUser())
return o_user.getUserType();
}
}catch(Exception e){
e.printStackTrace();
}
return 0;
}


%>
<%
IMG_SITE = "/servlet/Information.ReadImage?ImgId=";
%>
 
2010-02-11 22:11
bigpeach
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-11
收藏
得分:0 
错误信息中提到的InfoComm.jsp文件中的问题语句:User cannot be resolved to a type中的User类的源文件User.java:

//系统用户类
package Information;

import java.util.*;
import *;
import java.sql.*;
import java.text.*;
import comm.*;


public class User {
private String UserId; // 用户名
private String EmplName; // 员工姓名
private String PassWord; // 密码
private int UserType; // 用户类型;1-经理;2- 管理员

StringOper so = new StringOper();

// 获得一个用户的信息,如果存在此用户返回true,否则false
    public boolean getUser()throws Exception
    {
        int conditionNo = 0;
        DBOper o_DBOper = new DBOper();
        ResultSet rs = null;

String sql = "Select * from Users";
String condition = " where ";
// 设置查询条件
if(UserId != null){
            condition += "UserId='"+UserId+"'";
            conditionNo++;
        }
        if(PassWord != null)
        {
            if(conditionNo > 0)
            {
                condition += " and";
            }
            condition += " PassWord='"+PassWord+"'";
            conditionNo++;
        }
if(conditionNo > 0)
        {
            sql += condition;
        }
System.out.println(sql);
        try
        {
// 执行查询操作
            rs = o_DBOper.getResultSet(sql);
            if(rs.next())
            {
setUserId(so.ReplaceNull(rs.getString("UserId")));
setEmplName(so.ReplaceNull(rs.getString("EmplName")));
setPassWord(so.ReplaceNull(rs.getString("PassWord")));
setUserType(rs.getInt("UserType"));
                return true;
            }
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
        return false;
    }

// 根据查询条件获得多个用户信息
public Vector getMoreUser() throws Exception
    {
        Vector v_User = new Vector();
        int conditionNo = 0;

        DBOper o_DBOper = new DBOper();
        ResultSet rs = null;

        String sql = "Select * from Users";
        String condition = " where ";
        try
        {
            if(UserId != null)
            {
                condition += " UserId='"+UserId+"'";
                conditionNo++;
            }
            if(EmplName != null)
            {
                if(conditionNo > 0)
                {
                    condition += " and ";
                }
                condition += " EmplName='"+EmplName+"'";
                conditionNo++;
            }
if(UserType != 0)
            {
                if(conditionNo > 0)
                {
                    condition += " and ";
                }
                condition += " UserType="+UserType;
                conditionNo++;
            }
            if(conditionNo > 0)
            {
                sql += condition;
            }
            sql += " order by UserId desc";

            rs = o_DBOper.getResultSet(sql);
//System.out.println(sql);
while(rs.next())
            {
                User o_User2 = new User();
o_User2.setUserId(so.ReplaceNull(rs.getString("UserId")));
o_User2.setEmplName(so.ReplaceNull(rs.getString("EmplName")));
o_User2.setPassWord(so.ReplaceNull(rs.getString("PassWord")));
o_User2.setUserType(rs.getInt("UserType"));
                v_User.add(o_User2);
            }
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
        return v_User;
    }


//删除用户信息,条件为指定用户名
public void DeleteUser(String UserId) throws Exception
    {
        DBOper o_DBOper = new DBOper();
ResultSet rs = null;

        String sql_dlt = "delete from Users where UserId ='" + UserId + "'";
        try
        {
            o_DBOper.getResultSet(sql_dlt);
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
    }
//插入用户,密码缺省为6个1
public void CreateUser() throws Exception
    {
        DBOper o_DBOper = new DBOper();
        ResultSet rs = null;

        String sql = "Insert into Users(UserId,EmplName,UserType,PassWord) ";
sql =sql+"values('"+UserId+"','"+EmplName+"',"+UserType+",'111111')";
//System.out.println("INSERT SQL:"+sql);
        try
        {
            o_DBOper.getResultSet(sql);
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
    }
// 更新用户信息,用于管理员更改用户信息,不更改密码
public void UpdateUser() throws Exception
    {
        DBOper o_DBOper = new DBOper();
        ResultSet rs = null;

        String sql = "Update Users set EmplName='"+EmplName+"',UserType="+UserType;
sql = sql+" where UserId='"+UserId+"'";
// System.out.println("UPDATE SQL :"+sql);
        try
        {
            o_DBOper.getResultSet(sql);
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
    }
// 用户更改自己密码和管理员密码重置为六个1
public void UpdatePassWord() throws Exception
    {
        DBOper o_DBOper = new DBOper();
        ResultSet rs = null;

        String sql = "Update Users set PassWord='"+PassWord+"' where UserId='"+UserId+"'";
        try
        {
            o_DBOper.getResultSet(sql);
        }
        catch(Exception e)
        {
            throw new Exception(e.getMessage());
        }
    finally
    {
            try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
    }
    }
// 设置、获得用户的信息
public void setUserId(String UserId){
        this.UserId = UserId;
    }
    public String getUserId(){
        return this.UserId;
    }
public void setEmplName(String EmplName){
        this.EmplName = EmplName;
    }
    public String getEmplName(){
        return this.EmplName;
    }
public void setPassWord(String PassWord){
        this.PassWord = PassWord;
    }
    public String getPassWord(){
        return this.PassWord;
    }

public void setUserType(int UserType){
        this.UserType = UserType;
    }
    public int getUserType(){
        return this.UserType;
    }
}


谁知道是哪个地方有问题吗????????

我都快绝望了 !!
2010-02-11 22:12
angeyccl
Rank: 2
等 级:论坛游民
帖 子:1
专家分:20
注 册:2010-2-17
收藏
得分:20 
我是大白 都不是小白了
感觉这些都是我将会用到的 还什么都不会
顶起来 希望有大侠帮你解决
2010-02-17 22:28
baifenghan
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:258
专家分:952
注 册:2006-3-17
收藏
得分:0 
回复 5楼 angeyccl
classes文件夹中包括comm和 Information文件夹,这两个文件夹中放着java文件)和images(里面是图片)。 ,问题就是在这里,classes中应该放的是相对应的class文件,而不是.java 文件,先使用javac将其编译一下,然后拷贝至classes目录,应该就OK了。
2010-02-28 05:00
kingyue
Rank: 2
等 级:论坛游民
威 望:1
帖 子:28
专家分:21
注 册:2009-6-17
收藏
得分:0 
端口号,怎么是9090呢?我的是8080,你改过了?
2010-03-02 10:34
快速回复:JSP + Tomcat 5.5 + SQL Server 2000 出错,始终找不到原因,帮忙看一 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020535 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved