Unable to compile class for JSP

R

ramesh

Please help i am having this error for the past 3 day, but i wasn't
able rectify this error, pls help me,

Step 1: my context-->
<Context path="/site" docBase="e:/project" debug="0"
reloadable="true" crossContext="true" />

Step 2:
Files:
e:/project/
registration/
registration1.htm
registration2.jsp
WEB-INF/
web.xml
classes/
UserDetails.class



This is html file(registration1.htm) to send the details to
registration2.jsp file, this file having one bean tag. but the server
raises the error and is Unable to compile the class for JSP



File#1
registration1.htm

<form action="registration2.jsp" method="post" name="reg"
onSubmit="return validate()">
<br>
<table>
<tr>
<td><b>Company Registration Process ...</b></td>
</tr>
</table>

<hr><br>
<table align=center>
<tr>
<td>User/Company name:</td>
<td><input type=text name=userid size=40>*</td>
</tr>
<tr>
<td>Password:</td>
<td><input type=Password name=password>*</td>
</tr>
<tr>
<td>Con Password:</td>
<td><input type=Password name=conPassword>*</td>
</tr>

<tr>
<td> Secret Question: </td>
<td>
<select name=secQuestion>
<Option value=""> ---Select---</option>
<option value="Favourate Pets Name">Favourate Pets
Name</option>
<option value="Favourate Spot">Favourate Spot</option>
<option value="Your Sign">Your Sign</option>
<option value="Alternative Question">Alternative
Question</option>
</select>
</td>
</tr>
<tr>
<td>Alternative Question:</td>
<td><input type=Text name=altQuestion size=40>*</td>
</tr>
<tr>
<td>Hint Answer:</td>
<td><input name=hintAnswer>*</td>
</tr>


<tr>
<td>Current E-Mail Address</td>
<td><input type=text name=emailAdd size=40></td>
</tr>
</table>

<p align=center>
<Input type=Submit name=Send value=" Next ">
<br><br><br><hr>
</form>

File#2
registration2.jsp

<%@ page import="java.util.*" %>


<%
String user_id = request.getParameter("userid");
String password = request.getParameter("password");
String u_sec_ques=request.getParameter("secQuestion");
if (u_sec_ques==null || u_sec_ques=="") {
u_sec_ques=request.getParameter("altQuestion");
}
String u_hint_ans=request.getParameter("hintAnswer");
String email = request.getParameter("emailAdd");
%>

<jsp:useBean id="myUserBean" class="UserDetails" scope="session" >
<jsp:setProperty name="myUserBean" property="userId" value="<%=
user_id %>" />
<jsp:setProperty name="myUserBean" property="password" value="<%=
password %>" />
<jsp:setProperty name="myUserBean" property="question" value="<%=
u_sec_ques %>" />
<jsp:setProperty name="myUserBean" property="ans" value="<%=
u_hint_ans %>" />
<jsp:setProperty name="myUserBean" property="email" value="<%=
email %>" />
</jsp:useBean>

<%
out.println(myUserBean.isExist());
%>


File#3
UserDetails.java


import java.sql.*;

public class UserDetails {

private String firstName = null;
private String lastName = null;
private String sex = null;
private String day = null;
private String month = null;
private Date bdate = null;
private String add1 = null;
private String add2 = null;
private String city = null;
private String state = null;
private String country = null;
private String pin = null;
private String ph1 = null;
private String ph2 = null;
private String fax = null;
private String userId = null;
private String password = null;
private String question = null;
private String ans = null;
private String email = null;


Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

public UserDetails() {}
public void setFirstName(String firsName) {
this.firstName = firstName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setBdate(Date bdate) {
this.bdate = bdate;
}

public void setAdd1(String add1) {
this.add1 = add1;
}

public void setAdd2(String add2) {
this.add2 = add2;
}

public void setCity(String city) {
this.city = city;
}

public void setState(String state) {
this.state = state;
}

public void setCountry(String country) {
this.country = country;
}

public void setPin(String pin) {
this.pin = pin;
}

public void setPh1(String ph1) {
this.ph1 = ph1;
}

public void setPh2(String ph2) {
this.ph2 = ph2;
}

public void setFax(String fax) {
this.fax = fax;
}

public void setUserId(String userId) {
this.userId = userId;
}

public void setPassword(String password) {
this.password = password;
}

public void setQuestion(String question) {
this.question = question;
}

public void setAns(String ans) {
this.ans = ans;
}

public void setEmail(String email) {
this.email = email;
}

public boolean isExist() {

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:eek:dbc:site_builder");
con.setAutoCommit(false);
}catch(Exception e) {
return true;
}

if(userId != null && !userId.equals("")) {
try {
pstmt = con.prepareStatement("select count(*) from user_table
where user_id=?");
pstmt.setString(1,userId);

rs = pstmt.executeQuery();
rs.next();

int count = rs.getInt(1);

if(count > 0) {
return true;
}
return false;
}catch(Exception e) {
return true;
}
}
return true;
}

public boolean isCreate() {
boolean flag = isExist();

if(flag) {
return false;
}

try {
pstmt = con.prepareStatement("insert into user_table
values(?,?,?,?,?)");
pstmt.setString(1,userId);
pstmt.setString(2,password);
pstmt.setString(3,question);
pstmt.setString(4,ans);
pstmt.setString(5,email);

int count = pstmt.executeUpdate();

if( count > 0 ) {
pstmt = con.prepareStatement("insert into user_det_table
values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
pstmt.setString(1,firstName+" "+lastName);
pstmt.setString(2,sex);
pstmt.setString(3,add1);
pstmt.setString(4,add2);
pstmt.setString(5,city);
pstmt.setString(6,state);
pstmt.setString(7,country);
pstmt.setString(8,pin);
pstmt.setString(9,ph1);
pstmt.setString(10,ph2);
pstmt.setString(11,fax);
pstmt.setString(12,userId);
pstmt.setDate(13,bdate);

int count1 = pstmt.executeUpdate();

if(count1 > 0 ) {
con.commit();
return true;
}
else {
con.rollback();
return false;
}
}else {
con.rollback();
return false;
}

}catch(Exception e) {
return false;
}
}

}
 
W

Wendy S

ramesh said:
Please help i am having this error for the past 3 day, but i wasn't
able rectify this error, pls help me,
WEB-INF/
web.xml
classes/
UserDetails.class

Production code belongs in named packages. This directory structure
indicates that the UserDetails is in the default package (no package
statement at the top). Package your code and the problem will most likely
go away.

There's a part of the JLS that says you cannot import a class in the default
package (no package statement) into a class in a named package. I think
that's what you're running into.

It would have been more useful to see the error message than everything you
posted.
 
S

Sudsy

ramesh said:
Please help i am having this error for the past 3 day, but i wasn't
able rectify this error, pls help me,

So what's the error (EXACT text please)? Also include your web.xml.
 
M

Michael Scovetta

I've had similar problems, I fixed it by putting the class into a
package and importing it from JSP. The app server should output the
compilation error. You can also try compiling the JSP directly with
JSPC/Jasper. It probably can't find UserDetails.

Oh, and please remember to .close() your Connections,
[Prepared]Statements, and Recordsets-- letting the GC do it is not a
good idea. I use a simple:

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DBFactory.getConnection(); // my own factory method
pstmt = conn.prepareStatement( /* Query */ );
rs = pstmt.executeQuery();

while (rs.next()) {
// whatever
}
} catch (SQLException ex) {
// Log the error
} finally {
DBFactory.close(conn, pstmt, rs);
}

Where DBFactory.close() is the big nasty:
/**
* Closes connections to Connection, PreparedStatement, and
ResultSet objects.
* @param conn Connection object, null is alright
* @param pstmt PreparedStatement object, null is alright
* @param rs ResultSet object, null is alright
*/
public static void close( Connection conn,
PreparedStatement pstmt,
ResultSet rs ) {
if (rs != null)
try {
rs.close();
} catch (Exception e) {
}
if (pstmt != null)
try {
pstmt.close();
} catch (Exception e) {
}
if (conn != null)
try {
conn.close();
} catch (Exception e) {
}
}



M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,375
Members
47,020
Latest member
anuradha

Latest Threads

Top