JSP Help Needed

S

sdavids

Hey everyone I am trying to learn JSP although keep running into a
brick wall. I set up Tomcat 5.5 which is running fine, but I am trying
to import a Java class into a JSP page and it doesnt seem to work, this
is what my class looks like:

package steve;

public class TestMe {

public TestMe(){
System.out.println("INSIDE CONSTRUCTOR");
}

public int getNumber(){
return 10;
}
}

I saved the class as TestMe, and saved it in "\WEB-INF\classes\steve"

Now my JSP code is as follows:

<html>
<%@ page import="steve.TestMe.*" %>
<body>
<%
TestMe temp = new TestMe();
out.print("NUM=" + temp.getNumber());
%>
</body>
</html>

The error which I recieve when I run the jsp file is: TestMe cannot be
resolved to a type.

Any help would be phenominal.
 
N

nkalagarla

There is a problem in your import.

<%@ page import="steve.TestMe.*" %>

The above line should be like

<%@ page import="steve.*" %>
or
<%@ page import="steve.TestMe %>
 
S

sdavids

p.s. I didnt do anything with the web.xml file, I dont know if that is
a problem or not, I really dont know what to do with it - I was under
the impression you only needed to modify it if you wanted to do
scriplets and such.
 
S

sdavids

I still get the same errors after changing the import statements with
both of yours
 
N

nkalagarla

Did you compile your java file? If not compile your java file and put
it in WEB-INF\classes\steve.

Also import should be like.

<%@ page import="steve.*" %>
or
<%@ page import="steve.TestMe"%>
 
T

Thomas Fritsch

sdavids said:
Hey everyone I am trying to learn JSP although keep running into a
brick wall. I set up Tomcat 5.5 which is running fine, but I am trying
to import a Java class into a JSP page and it doesnt seem to work, this
is what my class looks like:

package steve;

public class TestMe {

public TestMe(){
System.out.println("INSIDE CONSTRUCTOR");
}

public int getNumber(){
return 10;
}
}

I saved the class as TestMe, and saved it in "\WEB-INF\classes\steve"
You have to save the class file as "TestMe.class", not as "TestMe".
 
S

sdavids

Yes I have compiled the class, and I placed TestMe.class as well as
TestMe.java into the directory. Is there anything that I need to do in
the web..xml file in order for the jsp and java file to talk to one
another?
 
T

Timo Stamm

sdavids said:
Yes I have compiled the class, and I placed TestMe.class as well as
TestMe.java into the directory.

Into which directory? It should be in

<webroot>/WEB-INF/classes/steve/TestMe.class


The JSP page can be anywhere in <webroot> (except restricted
directories). The import statement must be

steve.TestMe

or

steve.*


If that doesn't work, try importing a standard Java class like
java.util.ArrayList. If that works, add

static void main(String[] args) {System.out.println("hello world");}

to TestMe and try to run it with javac.

In other words: isolate the problem.

Is there anything that I need to do in
the web..xml file in order for the jsp and java file to talk to one
another?

No.


Timo
 
S

sdavids

The JSP page can be anywhere in <webroot> (except restricted
directories). The import statement must be

steve.TestMe

When I do that I get the error:
Generated servlet error:
Only a type can be imported. steve.TestMe resolves to a package

or

steve.*
Yet again it wont let me declare a new item of the TestMe type within
the JSP file, saying "TestMe cannot be resolved to a type"
 
T

Thomas Fritsch

sdavids said:
When I do that I get the error:
Generated servlet error:
Only a type can be imported. steve.TestMe resolves to a package
To me this error message sounds pretty much that you might have a
*directory* "steve/TestMe" in your WEB-INF/classes area, instead of
having a *file* "steve/TestMe.class". I would suggest to carefully check
your WEB-INF/classes directory tree and mnaybe to delete and rebuild it
from scratch.
 
S

sdavids

Nope, my folder setup is as follows: "\WEB-INF\classes\steve" and
within the steve directory, I have TestMe.class and TestMe.java
 
Joined
Oct 3, 2006
Messages
1
Reaction score
0
Hey, I dont' know if you found out the problem or not but I just had the same problem, did everything in my power to figure it out... finally I rebooted tomcat and voila... the world was right again. I'm pretty sure that's all you're going to have to do.
Now every time I update a class, I have to reboot tomcat so it can register that I've changed a library file. There's probably a way to do it without rebooting but who cares. It works.
 
Joined
May 8, 2009
Messages
1
Reaction score
0
I had the same problem. :captain:

I had all nesessary .jar's included (commons-fileupload-1.2.1.jar AND commons-io-1.4.jar).

However the error ocurred still.

In my case the reason for the error was that one of dependency .jar's (commons-io-1.4.jar)

was included, BUT not yet phisically present in my "lib" folder: \build\web\WEB-INF\lib\



SOLUTION: hit "Clear and Build" !
and the error is gone.
 
Joined
Oct 30, 2012
Messages
2
Reaction score
0
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<html>
<head>
<%@ page import ="net.sf.mpxj.ProjectFile ,net.sf.mpxj.MPXJException ,net.sf.mpxj.Resource ,
net.sf.mpxj.Task ,
net.sf.mpxj.mpp.MPPReader ,
net.sf.mpxj.reader.ProjectReader;" %>

<title>Insert title here</title>
</head>
<body>


<%
final class Mpx
{

public void mppReader()
{
ProjectReader reader = new MPPReader();
ProjectFile project;
System.out.print("before reading");
try
{

project = reader.read("b4ubuild_sample_2k-03.mpp");
//b4ubuild_sample_2k-03
}
catch (MPXJException e)
{

e.printStackTrace();
}

for (Resource resource : project.getAllResources())
{

System.out.println("Resource: " + resource.getName() + " \n(Unique ID=" +resource.getUniqueID() + ")");
System.out.println("\n");
}


for (Task task : project.getAllTasks())
{
System.out.println("Task: " + task.getName() + " ID=" + task.getID() + " Unique ID=" +
task.getUniqueID()+ "\nStart Date : " +task.getStart()+"\nFinish Date : "+task.getFinish()+ "\nDuration : "
+task.getDuration().getDuration());
System.out.println("\n");
}

System.out.println("after reading");
}
public void main(String[] args)
{
Mpx fileReader = new Mpx();
fileReader.mppReader();
}
}%>
</body>
</html>
 

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

Similar Threads

JSP/JavaBean - Newbie help 1
javaBeans and JSP 2
Help in hangman game 1
Tomcat JSP importing class error 7
JSP problem 5
Java and jsp codes 4
jsp and usebeans 1
unable to compile login jsp code 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top