0

Hi,
I am new to jsp, and Beans. I have been working on this piece of code, for the past week and I am no further along :'(

I am using Tomcat Apache 6.0
In the ROOT folder I have a simple page test1.jsp:

package user;
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="userDetails" class="user.UserDetails" scope="session" />
<jsp:setProperty name = "hopeThisWorks" property="*"/>
<% userDetails.getData(); %>
<!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=utf-8" />
<title>hello</title>
</head>

<body>
test 1
</body>
</html>

I have a java class in: WEB-INF\classes\user called UserDetails

Which I have attached.

I keep getting the error:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: user/UserDetails (wrong name: java/user/UserDetails)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:275)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

As I said I have been working on it, and gotten no where, someone please help!!!

Thanks, Andrew

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Attachments
// based on: http://www.stardeveloper.com/forums/thread.asp?thread_id=1484
import java.io.*;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.net.*;

public class UserDetails
{
	String[] firstName;
	String[] surName;
	String[] userName;
	String[] password;
	int[] userNo;
	int z; // used as counter
	int i = 0;
	int numberOfUsers = 0;

	public UserDetails() 
	{
	}

	public void getData()
	{
		Connection con = null;
		
		try 
		{
			//Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection("jdbc:mysql://localhost_3306","root", "password");
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("SELECT * FROM userDetails");
			
			
			while(rs.next())
			{	
					
					numberOfUsers++;
			}

			firstName = new String[numberOfUsers];
			surName = new String[numberOfUsers];
			userName = new String[numberOfUsers];
			password = new String[numberOfUsers];
			userNo = new int[numberOfUsers];

			while(rs.next())
			{	
					firstName[i]=(rs.getString("firstName"));
					surName[i] = (rs.getString("surName"));
					userName[i] = (rs.getString("userName"));
					password[i] = (rs.getString("password"));
					userNo[i] = (rs.getInt("userNo"));

					
					i++;
			}
		} 
		catch(Exception e) 
		{
			e.printStackTrace();
			System.out.println("Exception: " + e.getMessage());
		} 
		finally 
		{
			try 
			{
				if(con != null)
				con.close();
			} 
			catch(SQLException e) 
			{
			}
		}
	}
	
	public boolean checkName(String testName)
	{
		boolean checked = false;
		for (z=0;z<numberOfUsers;z++)
		{
			if ((userName[z].compareTo(testName)) > 1)
			{
				checked = true;
				return checked;
			}
		}
		return false;
	}
	
	public boolean checkPassword(String testPassword)
	{
		boolean checked = false;
		for (z=0;z<numberOfUsers;z++)
		{
			if ((password[z].compareTo(testPassword)) > 1)
			{
				checked = true;
				return checked;
			}
		}
		return false;
	}
	
	private int returnNumber()
	{
		return numberOfUsers;
	}
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by peter_budo
0

You have package declaration on the top of JSP which is not need it, but you are missing package declaration in your UserDetails where obviously is need it...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.