Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error when i run a jsp file

 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying some sample applications that came with Sams Teach Yourself JSP.

When I run one of these I get the following error:

org.apache.jasper.JasperException: /ch07/ch07_09.jsp(9,8) The value for the useBean class attribute beans.ch07_07 is invalid.

The jsp file that I have is pasted below. Is there something wrong with the path. Because the javabean was compiled correctly and I have saved the file under the folder of Tomcat - webapps\Sams-TY-JSP\ch07\WEB-INF\classes\beans
while the jsp page is in webapps\Sams-TY-JSP\ch07

I ran a few other examples and they ran ok. But with this one I am having problems.

Can someone please advise what is wrong here.

Thanks
Ricky

<HTML>
<HEAD>
<TITLE>Using Beans and Session Scope</TITLE>
</HEAD>

<BODY>
<H1>Using Beans and Session Scope</H1>

<jsp:useBean id="bean1" class="beans.ch07_07" scope="session" />

<%
bean1.setCounter(bean1.getCounter() + 1);
%>
The counter value is: <jsp:getProperty name="bean1" property="counter" />
</BODY>
</HTML>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ricky James:
and I have saved the file under the folder of Tomcat - webapps\Sams-TY-JSP\ch07\WEB-INF\classes\beans


You saved the .class file under that directory, right?
Not just the .java file?
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


You saved the .class file under that directory, right?
Not just the .java file?


Yes it has the class file and also the java file.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The .java file is completely unecessary. You should only be putting the .class files there.

So you most definitely have the file:



in the WEB-INF of the current context (web app)?

P.S. Please don't use bold to post code. It makes is incredibly difficult to read. Rather, use UBB code tags. Please read this for more info.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't your application structure be something like :
"webapps\Sams-TY-JSP\WEB-INF\classes\ch07\beans"

The WEB-INF directory is supposed to be at the root of your application (called Sams-TY-JSP).

You would then have to change the package declaration of your bean files into :


And then in your JSP files as well :



PS : ch07_07 is a very depressing name for a class ;) Something like "Ch07Ex07.java" would be more like it.
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
The .java file is completely unecessary. You should only be putting the .class files there.

So you most definitely have the file:



in the WEB-INF of the current context (web app)?

P.S. Please don't use bold to post code. It makes is incredibly difficult to read. Rather, use UBB code tags. Please read this for more info.


Thanks for the reply Bear. I'll use UBB tags from now on.

About the exercise:

Yes I most definitely have the file in that folder. And I am really confused why this isn't working.

Thanks again.
Rikcy
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
Shouldn't your application structure be something like :
"webapps\Sams-TY-JSP\WEB-INF\classes\ch07\beans"

The WEB-INF directory is supposed to be at the root of your application (called Sams-TY-JSP).

You would then have to change the package declaration of your bean files into :


And then in your JSP files as well :



PS : ch07_07 is a very depressing name for a class ;) Something like "Ch07Ex07.java" would be more like it.


Thanks for the reply Satou.

I had the class files in webapps\Sams-TY-JSP\ch07\WEB-INF\classes\beans. Following your advice I copy-pasted the folder ch07 in webapps directory. And now it is working!!

I got it, I think!

Thanks again.
Ricky
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[qutoe]I got it, I think!
Make sure you really got it ;) You'd better understand how web applications are structured to avoid hair-pulling problems.
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
[qutoe]I got it, I think!

Make sure you really got it ;) You'd better understand how web applications are structured to avoid hair-pulling problems.

Thanks for the advice. You are correct.

I am doing some reading on this topic.

Cheers
Ricky
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
Shouldn't your application structure be something like :
"webapps\Sams-TY-JSP\WEB-INF\classes\ch07\beans"


Nice catch.
I missed that in the original post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic