I'm aware that this is a popular error:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 19 in the jsp file: /sample.jsp
Connection.Connect cannot be resolved to a type
16: try
17: {
18:
19: Connection.Connect con = new Connection.Connect();
20: ResultSet rs = con.execute(query);
21:
22: int numCols = rs.getMetaData().getColumnCount();
An error occurred at line: 19 in the jsp file: /sample.jsp
Connection.Connect cannot be resolved to a type
16: try
17: {
18:
19: Connection.Connect con = new Connection.Connect();
20: ResultSet rs = con.execute(query);
21:
22: int numCols = rs.getMetaData().getColumnCount();
From most solutions, it appears that I misplaced the java class.
However, I've placed the Connect class in WEB-INF/classes/Connection/,
which was what was recommended by most. This is the error I still
received.
I'm sorry, but is there something I'm doing wrong?
|
|
0
|
|
|
|
Reply
|
vsector (1)
|
12/1/2009 1:41:52 AM |
|
Ah, right. This is the code I was using.
<h3>JSP and JDBC</h3>
<hr>
<%-- JSP directive --%>
<%@ page import="java.net.*, java.io.*, java.sql.*, java.util.*"
%>
<%-- JSP scriplet --%>
<%
String query=request.getParameter("query");
try
{
Connection.Connect con = new Connection.Connect
();
ResultSet rs = con.execute(query);
int numCols = rs.getMetaData().getColumnCount
();
%><TABLE BORDER=2 ALIGN=LEFT><%
%><TR><%
int j=0;
for (j=1; j<=numCols; j++)
out.println("<TH>"+
rs.getMetaData().getColumnName(j)+"</TH>");
%></TR><%
while (rs.next())
{
%><TR><%
int i=0;
for (i=1; i<=numCols; i++)
out.println("<TD>"+rs.getString(i)+"</
TD>");
%></TR><%
}
%></TABLE><%
con.close();
}
catch (Exception e)
{out.println(e.toString());}
%>
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 1:53:56 AM
|
|
Vincent Ly wrote:
> I'm aware that this is a popular error:
>
> org.apache.jasper.JasperException: Unable to compile class for JSP:
>
> An error occurred at line: 19 in the jsp file: /sample.jsp
> Connection.Connect cannot be resolved to a type
> 16: try
> 17: {
> 18:
> 19: Connection.Connect con = new Connection.Connect();
> 20: ResultSet rs = con.execute(query);
> 21:
> 22: int numCols = rs.getMetaData().getColumnCount();
>
>
> An error occurred at line: 19 in the jsp file: /sample.jsp
> Connection.Connect cannot be resolved to a type
> 16: try
> 17: {
> 18:
> 19: Connection.Connect con = new Connection.Connect();
> 20: ResultSet rs = con.execute(query);
> 21:
> 22: int numCols = rs.getMetaData().getColumnCount();
>
> From most solutions, it appears that I misplaced the java class.
> However, I've placed the Connect class in WEB-INF/classes/Connection/,
> which was what was recommended by most. This is the error I still
> received.
>
> I'm sorry, but is there something I'm doing wrong?
So you have a:
WEB-INF/classes/Connection/Connect.class
and Connect.java has:
package Connection;
in the top?
Arne
|
|
0
|
|
|
|
Reply
|
ISO
|
12/1/2009 2:26:59 AM
|
|
Yes, the Connect.java has package Connection at the top.
You answered a question similar to this in the past; I've reviewed the
response you've made to that question and made the changes
accordingly. But, the problem still persists.
Thanks for your help.
On Nov 30, 9:26=A0pm, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
> Vincent Ly wrote:
> > I'm aware that this is a popular error:
>
> > org.apache.jasper.JasperException: Unable to compile class for JSP:
>
> > An error occurred at line: 19 in the jsp file: /sample.jsp
> > Connection.Connect cannot be resolved to a type
> > 16: =A0 =A0 =A0 =A0 =A0 =A0 try
> > 17: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > 18:
> > 19: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection.Connect con =3D new Conne=
ction.Connect();
> > 20: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResultSet rs =3D con.execute(query)=
;
> > 21:
> > 22: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int numCols =3D rs.getMetaData().ge=
tColumnCount();
>
> > An error occurred at line: 19 in the jsp file: /sample.jsp
> > Connection.Connect cannot be resolved to a type
> > 16: =A0 =A0 =A0 =A0 =A0 =A0 try
> > 17: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > 18:
> > 19: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection.Connect con =3D new Conne=
ction.Connect();
> > 20: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ResultSet rs =3D con.execute(query)=
;
> > 21:
> > 22: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int numCols =3D rs.getMetaData().ge=
tColumnCount();
>
> > From most solutions, it appears that I misplaced the java class.
> > However, I've placed the Connect class in WEB-INF/classes/Connection/,
> > which was what was recommended by most. =A0This is the error I still
> > received.
>
> > I'm sorry, but is there something I'm doing wrong?
>
> So you have a:
>
> WEB-INF/classes/Connection/Connect.class
>
> and Connect.java has:
>
> package Connection;
>
> in the top?
>
> Arne
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 2:32:59 AM
|
|
Please do not top-post (corrected).
Arne Vajhøj wrote:
>> So you have a:
>>
>> WEB-INF/classes/Connection/Connect.class
>>
>> and Connect.java has:
>>
>> package Connection;
>>
>> in the top?
Vincent Ly wrote:
> Yes, the Connect.java has package Connection at the top.
That partially (by which I mean incompletely) answers his second question, but
what was the answer to his first question?
>> So you have a:
>>
>> WEB-INF/classes/Connection/Connect.class ...?
--
Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
12/1/2009 2:56:13 AM
|
|
On Nov 30, 9:56=A0pm, Lew <no...@lewscanon.com> wrote:
> Please do not top-post (corrected).
>
> Arne Vajh=F8j wrote:
> >> So you have a:
>
> >> WEB-INF/classes/Connection/Connect.class
>
> >> and Connect.java has:
>
> >> package Connection;
>
> >> in the top?
> Vincent Ly wrote:
> > Yes, the Connect.java has package Connection at the top.
>
> That partially (by which I mean incompletely) answers his second question=
, but
> what was the answer to his first question?
>
> >> So you have a:
>
> >> WEB-INF/classes/Connection/Connect.class ...?
>
> --
> Lew
Sorry, I was under the impression that he was making a statement.
To clarify:
I have a Connect class in WEB-INF/classes/Connection/; in other words:
WEB-INF/classes/Connection/Connect.class exists.
And in Connect.java used to create the Connect.class, I have "package
Connection;" at the top.
Would it be helpful to see the actual class?
What does top-post mean? Replying on top of a quote?
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 3:27:29 AM
|
|
Vincent Ly wrote:
> On Nov 30, 9:56 pm, Lew <no...@lewscanon.com> wrote:
>> Please do not top-post (corrected).
>> Arne Vajh�j wrote:
>>>> So you have a:
>>>> WEB-INF/classes/Connection/Connect.class
>>>> and Connect.java has:
>>>> package Connection;
>>>> in the top?
>> Vincent Ly wrote:
>>> Yes, the Connect.java has package Connection at the top.
>> That partially (by which I mean incompletely) answers his second question, but
>> what was the answer to his first question?
>>
>>>> So you have a:
>>>> WEB-INF/classes/Connection/Connect.class ...?
>
> Sorry, I was under the impression that he was making a statement.
>
> To clarify:
>
> I have a Connect class in WEB-INF/classes/Connection/; in other words:
>
> WEB-INF/classes/Connection/Connect.class exists.
>
> And in Connect.java used to create the Connect.class, I have "package
> Connection;" at the top.
And you restarted Tomcat after putting the class there?
> Would it be helpful to see the actual class?
Most likely not.
But if the likely does not turn up solving the problem, then we may
need to look at the unlikely.
> What does top-post mean? Replying on top of a quote?
Yes.
Arne
|
|
0
|
|
|
|
Reply
|
ISO
|
12/1/2009 3:45:45 AM
|
|
On Nov 30, 10:45=A0pm, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
> Vincent Ly wrote:
> > On Nov 30, 9:56 pm, Lew <no...@lewscanon.com> wrote:
> >> Please do not top-post (corrected).
> >> Arne Vajh=F8j wrote:
> >>>> So you have a:
> >>>> WEB-INF/classes/Connection/Connect.class
> >>>> and Connect.java has:
> >>>> package Connection;
> >>>> in the top?
> >> Vincent Ly wrote:
> >>> Yes, the Connect.java has package Connection at the top.
> >> That partially (by which I mean incompletely) answers his second quest=
ion, but
> >> what was the answer to his first question?
>
> >>>> So you have a:
> >>>> WEB-INF/classes/Connection/Connect.class ...?
>
> > Sorry, I was under the impression that he was making a statement.
>
> > To clarify:
>
> > I have a Connect class in WEB-INF/classes/Connection/; in other words:
>
> > WEB-INF/classes/Connection/Connect.class exists.
>
> > And in Connect.java used to create the Connect.class, I have "package
> > Connection;" at the top.
>
> And you restarted Tomcat after putting the class there?
>
> > Would it be helpful to see the actual class?
>
> Most likely not.
>
> But if the likely does not turn up solving the problem, then we may
> need to look at the unlikely.
>
> > What does top-post mean? =A0Replying on top of a quote?
>
> Yes.
>
> Arne
Yes, I've tried restarting Tomcat. The error is still there.
/usr/share/tomcat6/webapps/dbproject/WEB-INF/classes/Connection
is where I'm storing the Connect.class file.
It doesn't appear to have any mistakes regarding capitalization or
anything.
Thank you for your time.
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 4:10:31 AM
|
|
Vincent Ly <vsector@gmail.com> wrote:
>I'm aware that this is a popular error:
>
>org.apache.jasper.JasperException: Unable to compile class for JSP:
>
>An error occurred at line: 19 in the jsp file: /sample.jsp
>Connection.Connect cannot be resolved to a type
>16: try
>17: {
>18:
>19: Connection.Connect con = new Connection.Connect();
Maybe it's just me, but I don't understand this. The "new" command is
used with a class name, it invokes the proper constructor and creates
a new instance of the class. Using "new" with a method makes no sense
to me. Also, "Connection" is an interface, and has no constructor. To
get one you use the getConnection static method of the DriverManager
class.
Looks to me like it should be something like:
Connection con =
DriverManager.getConnection(<arguments here>);
--
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt
|
|
0
|
|
|
|
Reply
|
Tim
|
12/1/2009 2:01:33 PM
|
|
Vincent Ly wrote:
>> I'm aware that this is a popular error:
>>
>> org.apache.jasper.JasperException: Unable to compile class for JSP:
>>
>> An error occurred at line: 19 in the jsp file: /sample.jsp
>> Connection.Connect cannot be resolved to a type
>> 16: try
>> 17: {
>> 18:
>> 19: Connection.Connect con = new Connection.Connect();
Tim Slattery wrote:
> Maybe it's just me, but I don't understand this. The "new" command is
> used with a class name, it invokes the proper constructor and creates
> a new instance of the class. Using "new" with a method makes no sense
Since he's using it with a constructor that isn't a problem. You've been
thrown off by the OP's unconventional capitalizing a package name.
> to me. Also, "Connection" is an interface, and has no constructor. To
No, 'Connection' is not an interface here.
> get one you use the getConnection static method of the DriverManager
> class.
>
> Looks to me like it should be something like:
> Connection con =
> DriverManager.getConnection(<arguments here>);
This would not work since in the OP's code 'Connection' is a package.
To the OP: By convention, package names are spelled in all lower-case,
particularly when there is a risk of confusion with a well-known type. Also,
your code might have been clearer with an 'import' and simple class names.
Also, naming a type with a verb is rather confusing; verbs are conventionally
used as method names and nouns or adjectives are used as type names. Tim's
confusion is understandable, for all that it could have been avoided with
very, very careful reading of your post.
--
Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
12/1/2009 2:38:29 PM
|
|
On Dec 1, 9:38=A0am, Lew <no...@lewscanon.com> wrote:
> Vincent Ly wrote:
> >> I'm aware that this is a popular error:
>
> >> org.apache.jasper.JasperException: Unable to compile class for JSP:
>
> >> An error occurred at line: 19 in the jsp file: /sample.jsp
> >> Connection.Connect cannot be resolved to a type
> >> 16: =A0 =A0 =A0 =A0 =A0 =A0 try
> >> 17: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> >> 18:
> >> 19: =A0 =A0 =A0 =A0 =A0 =A0Connection.Connect con =3D new Connection.C=
onnect();
> Tim Slattery wrote:
> > Maybe it's just me, but I don't understand this. The "new" command is
> > used with a class name, it invokes the proper constructor and creates
> > a new instance of the class. Using "new" with a method makes no sense
>
> Since he's using it with a constructor that isn't a problem. =A0You've be=
en
> thrown off by the OP's unconventional capitalizing a package name.
>
> > to me. Also, "Connection" is an interface, and has no constructor. To
>
> No, 'Connection' is not an interface here.
>
> > get one you use the getConnection static method of the DriverManager
> > class.
>
> > Looks to me like it should be something like:
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection con =3D
> > DriverManager.getConnection(<arguments here>);
>
> This would not work since in the OP's code 'Connection' is a package.
>
> To the OP: =A0By convention, package names are spelled in all lower-case,
> particularly when there is a risk of confusion with a well-known type. =
=A0Also,
> your code might have been clearer with an 'import' and simple class names=
..
> Also, naming a type with a verb is rather confusing; verbs are convention=
ally
> used as method names and nouns or adjectives are used as type names. =A0T=
im's
> confusion is understandable, for all that it could have been avoided with
> very, very careful reading of your post.
>
> --
> Lew
I see, that makes sense. I'll try reorganizing the code a bit then.
Thanks.
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 5:15:23 PM
|
|
On Dec 1, 12:15=A0pm, Vincent Ly <vsec...@gmail.com> wrote:
> On Dec 1, 9:38=A0am, Lew <no...@lewscanon.com> wrote:
>
>
>
> > Vincent Ly wrote:
> > >> I'm aware that this is a popular error:
>
> > >> org.apache.jasper.JasperException: Unable to compile class for JSP:
>
> > >> An error occurred at line: 19 in the jsp file: /sample.jsp
> > >> Connection.Connect cannot be resolved to a type
> > >> 16: =A0 =A0 =A0 =A0 =A0 =A0 try
> > >> 17: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > >> 18:
> > >> 19: =A0 =A0 =A0 =A0 =A0 =A0Connection.Connect con =3D new Connection=
..Connect();
> > Tim Slattery wrote:
> > > Maybe it's just me, but I don't understand this. The "new" command is
> > > used with a class name, it invokes the proper constructor and creates
> > > a new instance of the class. Using "new" with a method makes no sense
>
> > Since he's using it with a constructor that isn't a problem. =A0You've =
been
> > thrown off by the OP's unconventional capitalizing a package name.
>
> > > to me. Also, "Connection" is an interface, and has no constructor. To
>
> > No, 'Connection' is not an interface here.
>
> > > get one you use the getConnection static method of the DriverManager
> > > class.
>
> > > Looks to me like it should be something like:
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection con =3D
> > > DriverManager.getConnection(<arguments here>);
>
> > This would not work since in the OP's code 'Connection' is a package.
>
> > To the OP: =A0By convention, package names are spelled in all lower-cas=
e,
> > particularly when there is a risk of confusion with a well-known type. =
=A0Also,
> > your code might have been clearer with an 'import' and simple class nam=
es.
> > Also, naming a type with a verb is rather confusing; verbs are conventi=
onally
> > used as method names and nouns or adjectives are used as type names. =
=A0Tim's
> > confusion is understandable, for all that it could have been avoided wi=
th
> > very, very careful reading of your post.
>
> > --
> > Lew
>
> I see, that makes sense. =A0I'll try reorganizing the code a bit then.
>
> Thanks.
So, I changed Connect.java to DBConnection.java and removed the
package. I moved the DBConnection.class to
>/usr/share/tomcat6/webapps/dbproject/WEB-INF/classes/DBConnection.class
I also changed the
>Connection.Connect con =3D new Connection.Connect();
to
>DBConnection con =3D new DBConnection();
Am I doing it correctly so far? I'm still getting the same error. Is
there a scenario where that error may show without the directory tree
or syntax being the problem?
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 5:40:37 PM
|
|
On Dec 1, 12:40=A0pm, Vincent Ly <vsec...@gmail.com> wrote:
> On Dec 1, 12:15=A0pm, Vincent Ly <vsec...@gmail.com> wrote:
>
>
>
> > On Dec 1, 9:38=A0am, Lew <no...@lewscanon.com> wrote:
>
> > > Vincent Ly wrote:
> > > >> I'm aware that this is a popular error:
>
> > > >> org.apache.jasper.JasperException: Unable to compile class for JSP=
:
>
> > > >> An error occurred at line: 19 in the jsp file: /sample.jsp
> > > >> Connection.Connect cannot be resolved to a type
> > > >> 16: =A0 =A0 =A0 =A0 =A0 =A0 try
> > > >> 17: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > > >> 18:
> > > >> 19: =A0 =A0 =A0 =A0 =A0 =A0Connection.Connect con =3D new Connecti=
on.Connect();
> > > Tim Slattery wrote:
> > > > Maybe it's just me, but I don't understand this. The "new" command =
is
> > > > used with a class name, it invokes the proper constructor and creat=
es
> > > > a new instance of the class. Using "new" with a method makes no sen=
se
>
> > > Since he's using it with a constructor that isn't a problem. =A0You'v=
e been
> > > thrown off by the OP's unconventional capitalizing a package name.
>
> > > > to me. Also, "Connection" is an interface, and has no constructor. =
To
>
> > > No, 'Connection' is not an interface here.
>
> > > > get one you use the getConnection static method of the DriverManage=
r
> > > > class.
>
> > > > Looks to me like it should be something like:
> > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection con =3D
> > > > DriverManager.getConnection(<arguments here>);
>
> > > This would not work since in the OP's code 'Connection' is a package.
>
> > > To the OP: =A0By convention, package names are spelled in all lower-c=
ase,
> > > particularly when there is a risk of confusion with a well-known type=
.. =A0Also,
> > > your code might have been clearer with an 'import' and simple class n=
ames.
> > > Also, naming a type with a verb is rather confusing; verbs are conven=
tionally
> > > used as method names and nouns or adjectives are used as type names. =
=A0Tim's
> > > confusion is understandable, for all that it could have been avoided =
with
> > > very, very careful reading of your post.
>
> > > --
> > > Lew
>
> > I see, that makes sense. =A0I'll try reorganizing the code a bit then.
>
> > Thanks.
>
> So, I changed Connect.java to DBConnection.java and removed the
> package. =A0I moved the DBConnection.class to
>
> >/usr/share/tomcat6/webapps/dbproject/WEB-INF/classes/DBConnection.class
>
> I also changed the
>
> >Connection.Connect con =3D new Connection.Connect();
> to
> >DBConnection con =3D new DBConnection();
>
> Am I doing it correctly so far? =A0I'm still getting the same error. =A0I=
s
> there a scenario where that error may show without the directory tree
> or syntax being the problem?
I seemed to have solved the problem.
Thanks Arne, Lew, and Tim for all your patience with me.
It's a bit mysterious, but it seems javac with the -d options works
better than mkdir.
|
|
0
|
|
|
|
Reply
|
Vincent
|
12/1/2009 6:42:07 PM
|
|
Vincent Ly wrote:
>> So, I changed Connect.java to DBConnection.java and removed the
>> package. =A0I moved the DBConnection.class to
>
>> /usr/share/tomcat6/webapps/dbproject/WEB-INF/classes/DBConnection.class
>
You should assiduously avoid putting classes in the default (unnamed)
package.
All non-toy code should use packages.
--
Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
12/1/2009 9:37:15 PM
|
|
Vincent Ly wrote:
> On Dec 1, 12:40 pm, Vincent Ly <vsec...@gmail.com> wrote:
>> On Dec 1, 12:15 pm, Vincent Ly <vsec...@gmail.com> wrote:
>>
>>
>>
>>> On Dec 1, 9:38 am, Lew <no...@lewscanon.com> wrote:
>>>> Vincent Ly wrote:
>>>>>> I'm aware that this is a popular error:
>>>>>> org.apache.jasper.JasperException: Unable to compile class for JSP:
>>>>>> An error occurred at line: 19 in the jsp file: /sample.jsp
>>>>>> Connection.Connect cannot be resolved to a type
>>>>>> 16: try
>>>>>> 17: {
>>>>>> 18:
>>>>>> 19: Connection.Connect con = new Connection.Connect();
>>>> Tim Slattery wrote:
>>>>> Maybe it's just me, but I don't understand this. The "new" command is
>>>>> used with a class name, it invokes the proper constructor and creates
>>>>> a new instance of the class. Using "new" with a method makes no sense
>>>> Since he's using it with a constructor that isn't a problem. You've been
>>>> thrown off by the OP's unconventional capitalizing a package name.
>>>>> to me. Also, "Connection" is an interface, and has no constructor. To
>>>> No, 'Connection' is not an interface here.
>>>>> get one you use the getConnection static method of the DriverManager
>>>>> class.
>>>>> Looks to me like it should be something like:
>>>>> Connection con =
>>>>> DriverManager.getConnection(<arguments here>);
>>>> This would not work since in the OP's code 'Connection' is a package.
>>>> To the OP: By convention, package names are spelled in all lower-case,
>>>> particularly when there is a risk of confusion with a well-known type. Also,
>>>> your code might have been clearer with an 'import' and simple class names.
>>>> Also, naming a type with a verb is rather confusing; verbs are conventionally
>>>> used as method names and nouns or adjectives are used as type names. Tim's
>>>> confusion is understandable, for all that it could have been avoided with
>>>> very, very careful reading of your post.
>>> I see, that makes sense. I'll try reorganizing the code a bit then.
>>> Thanks.
>> So, I changed Connect.java to DBConnection.java and removed the
>> package. I moved the DBConnection.class to
>>
>>> /usr/share/tomcat6/webapps/dbproject/WEB-INF/classes/DBConnection.class
>> I also changed the
>>
>>> Connection.Connect con = new Connection.Connect();
>> to
>>> DBConnection con = new DBConnection();
>> Am I doing it correctly so far? I'm still getting the same error. Is
>> there a scenario where that error may show without the directory tree
>> or syntax being the problem?
>
> I seemed to have solved the problem.
Classes in default package is not good.
Especially not in JSP context !
> It's a bit mysterious, but it seems javac with the -d options works
> better than mkdir.
I fear that the problem will come back in either the same form
or a variation.
Arne
|
|
0
|
|
|
|
Reply
|
ISO
|
12/3/2009 2:41:07 AM
|
|
|
14 Replies
814 Views
(page loaded in 0.015 seconds)
|