This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes JasperException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JasperException" Watch "JasperException" New topic
Author

JasperException

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm just beginning to write jsp and i'm following this tutorial
i'm using eclipse, have a folder called projJsp, and inside it i've a folder called src and inside it i've my JSPs and also a package named bean where i've my Pessoa.java. I'm using tomcat5

here's my code:

when i click submit i get:
org.apache.jasper.JasperException: /src/SaveName2.jsp(1,1) The value for the useBean class attribute bean/Pessoa is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3270)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


as i'm totally new to jsp and related stuff, i guess its because i dont have anywhere my compiled java lass and also dont know how to refer to it..

can someone help me pls? (i also tried bean.Pessoa instead of bean/Pessoa)

TiA


java amateur
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

i also tried bean.Pessoa instead of bean/Pessoa


The dot-notation format is the correct one. The useBean action's class attribute requires the fully qualified class naem (not path) of the class.

You need to compile the bean and place the class file in the hiearch rooted at WEB-INF/classes.

So for this case, your class file should end up as WEB-INF/classes/bean/Pessoa.class


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks for your help, Bear

i'm i bit embarrassed: i know how to compile using command line or eclipse, when working with plain java apps, but, here, i dont know how to use eclipse to compile it for me

so i used command line, compiled and copied the .class to your folder structure, but i get the very same error msg

what am i doing wrong?

EDIT:
i made:
C:\Programas\Apache Software Foundation\Tomcat 5.5\webapps\myWebs\src\bean>javac Pessoa.java

C:\Programas\Apache Software Foundation\Tomcat 5.5\webapps\myWebs\src\bean>

then copied the .class just cretaed to your new path:

C:\Programas\Apache Software Foundation\Tomcat 5.5\webapps\myWebs\WEB-INF\classes\bean
[ October 01, 2005: Message edited by: miguel lisboa ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Sounds like your web app may not be set up correctly.

How are you running the web app? If it's through Eclipse you'll need to check with its docs to see how to set things up.

If you're running a stand-alone instance of Tomcat (recommend over letting an IDE do it for you, imho) I can give you a few tips to get you up and running.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
If you're running a stand-alone instance of Tomcat (recommend over letting an IDE do it for you, imho) I can give you a few tips to get you up and running.

i'd be quite grateful

actually i'm using eclipse just because of... inertia

the moment i reopened this window i was reading tomcat docs to see how they organize things:
The top-level directory of your web application hierarchy is also the document root of your application. Here, you will place the HTML files and JSP pages that comprise your application's user interface. When the system administrator deploys your application into a particular server, he or she assigns a context path to your application (a later section of this manual describes deployment on Tomcat). Thus, if the system administrator assigns your application to the context path /catalog, then a request URI referring to /catalog/index.html will retrieve the index.html file from your document root.

Standard Directory Layout
To facilitate creation of a Web Application Archive file in the required format, it is convenient to arrange the "executable" files of your web application (that is, the files that Tomcat actually uses when executing your app) in the same organization as required by the WAR format itself. To do this, you will end up with the following contents in your application's "document root" directory:

*.html, *.jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the client browser (such as JavaScript, stylesheet files, and images) for your application. In larger applications you may choose to divide these files into a subdirectory hierarchy, but for smaller apps, it is generally much simpler to maintain only a single directory for these files.


/WEB-INF/web.xml - The Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you. This file is discussed in more detail in the following subsection.


/WEB-INF/classes/ - This directory contains any Java class files (and associated resources) required for your application, including both servlet and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under /WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.


/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.
When you install an application into Tomcat (or any other 2.2/2.3-compatible server), the classes in the WEB-INF/classes/ directory, as well as all classes in JAR files found in the WEB-INF/lib/ directory, are made visible to other classes within your particular web application. Thus, if you include all of the required library classes in one of these places (be sure to check licenses for redistribution rights for any third party libraries you utilize), you will simplify the installation of your web application -- no adjustment to the system class path (or installation of global library files in your server) will be necessary.



as you can see my webapp is nothing special- just a tut, so if you dont mind pls go ahead

TiA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Well. it looks like you found the info I was going to give you. Make sure that your app is structured correctly according to that information, and make sure that you have a web app context set up that uses the folder containing the WEB-INF folder as the root of the context.

If all that is correct, the classes in WEB-INF/classes will automatically be added to the app's classpath.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
and make sure that you have a web app context set up that uses the folder containing the WEB-INF folder as the root of the context.

a few days ago i posted something related to this, because using server.xml to create a context wouldnt work; in the meanwhile i read that i could create a subdirectory called WEB-INF and inside create a web.xml file:


this is what i was using so far

as soon as i gather all this i'll post

thanks a lot!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

using server.xml to create a context wouldnt work


Why not? server.xml will work, but there are other means in Tomcat 5 to introduce a new context.

in the meanwhile i read that i could create a subdirectory called WEB-INF and inside create a web.xml file:


Yes you will need a web.xml. but that is in addition to, not in lieue of, defining a context.

Btw, the web.xml you posted is for older versions of Tomcat. What version are you using?
[ October 01, 2005: Message edited by: Bear Bibeault ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
5.5
what do i have to change?

EDIT
i rushed...
but there are other means in Tomcat 5 to introduce a new context

i'll look for, because i was thinking that creating that WEB-INF with xml file was enough...
[ October 01, 2005: Message edited by: miguel lisboa ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Firstly, get a copy of the Servlets 2.4 specification. You should have it (as well as a copy of the JSP 2.0 Spec) on your desktop. It explains much.

For a servlets 2.4 web app, you use a web.xml structured as such:


[ October 01, 2005: Message edited by: Bear Bibeault ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i downloaded both (.pdf), but now its family dinner time

once again thank you!
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i just turned on my lap, tried my app... and all worked fine!

i guess i just had to reboot, either windows or tomcat

EDIT:
to be more precise, i also got rid of src folder
[ October 02, 2005: Message edited by: miguel lisboa ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
as promised, here's what i got:
i created a root folder (projJsp)
inside i've my .html and .jsp files, build.xml and a folder WEB-INF; also have a package named bean where i've my .java files
inside WEB-INF i've web.xml and a folder named classes

here's my build.xml:
<?xml version = "1.0" encoding="ISO-8859-1" ?>



<project name = "projJsp" default = "build" basedir = ".">

<property name = "src.dir" value = "${basedir}" />

<property name = "build.dir" value = "${basedir}\WEB-INF\classes" />



<path id = "classpath">

<pathelement location = "${build.dir}" />

</path>



<target name = "init">

<mkdir dir = "${build.dir}" />

</target>



<target name = "build" depends = "init" description = "build all">

<javac

srcdir = "${src.dir}" destdir = "${build.dir}"

source = "1.5"

deprecation = "on" debug = "on" optimize = "off" includes = "**">

<classpath refid = "classpath" />

</javac>

</target>



<target name = "clean">

<delete dir = "${build.dir}" />

</target>



<target name = "rebuildAll" depends = "clean, build" description = "rebuild all" />

</project>


i wonder if anyone can teach me how i can trnaspose all of this to eclipse - making it use my ant file

TiA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

That would be a better question for the IDEs forum.
 
 
subject: JasperException
 
Similar Threads
Beans in JSP
jsp cannot call bean in websphere application server
JavaBean problem Tomcat 5.5
Error In Bean PageScope
getting variable value