You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ut...@accenture.com on 2005/06/09 15:50:56 UTC

Importing user-defined class in a JSP page

I'm new to programming in JSP/Tomcat. I am kinda held back with the
following simple situation.  I have database connection class that I'm
trying to import in my jsp file with no success so far (ChangePassword).
I am compiling with JDK1.4.2.08.
 
My JSP page is in 
$CATALINA_HOME/webapps/mywebapp/
 
I do have a web.xml file that is correctly configured with passwords and
values to allow the application to connect to the user directory.  This
is the stack trace of the error:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 85 in the jsp file: /changepw.jsp
Generated servlet error:
Invalid argument to operation ++/--


	
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHa
ndler.java:84)
	
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.ja
va:328)
	
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:39
7)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
	
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.ja
va:556)
	
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va: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)
Any ideas how to import a user-defined class in JSP, I mean where to
place the class file and is there anyother environment variable to set?
I read somewhere that if you are using jdk 1.4 and above, you need to
have package name for classes.  It said to Put your webappname class in
a package, compile it and then import it like the following in your JSP
file:  <%@ page import="packagename.WebAppName"%> 

Again, I am new to all of this so could you possibly help me with the
issue as well as helping me to understand the potential fix as outlined
above?  I would really appreciate any help you can provide.
 
Thanks


This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.

Re: Importing user-defined class in a JSP page

Posted by delbd <de...@oma.be>.
Supposing your class looks like the following:

package com.mycompany.mywebapp
public class MyClass {
}


then you need the following import directive 
<%@ page import="com.mycompany.mywebapp.MyClass"%>
or
<%@ page import="com.mycompany.mywebapp.*"%>

Please note, i see you have your error at line 85, don't forget your <%@ page 
import="..." %> directives must be at the top of the jps, not in the code

Also, compiled class must be either in 
WEB-INF/classes/com/mycompany/mywebapp/MyClass.class
or in a .jar file located in WEB-IF/lib/*.jar

Le Jeudi 9 Juin 2005 15:50, uttam.g.dubal@accenture.com a écrit :
> I'm new to programming in JSP/Tomcat. I am kinda held back with the
> following simple situation.  I have database connection class that I'm
> trying to import in my jsp file with no success so far (ChangePassword).
> I am compiling with JDK1.4.2.08.
>
> My JSP page is in
> $CATALINA_HOME/webapps/mywebapp/
>
> I do have a web.xml file that is correctly configured with passwords and
> values to allow the application to connect to the user directory.  This
> is the stack trace of the error:
> org.apache.jasper.JasperException: Unable to compile class for JSP
>
> An error occurred at line: 85 in the jsp file: /changepw.jsp
> Generated servlet error:
> Invalid argument to operation ++/--
>
>
>
> org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHa
> ndler.java:84)
>
> org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.ja
> va:328)
>
> org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:39
> 7)
> 	org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
> 	org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
> 	org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
>
> org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.ja
> va:556)
>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
> va: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)
> Any ideas how to import a user-defined class in JSP, I mean where to
> place the class file and is there anyother environment variable to set?
> I read somewhere that if you are using jdk 1.4 and above, you need to
> have package name for classes.  It said to Put your webappname class in
> a package, compile it and then import it like the following in your JSP
> file:  <%@ page import="packagename.WebAppName"%>
>
> Again, I am new to all of this so could you possibly help me with the
> issue as well as helping me to understand the potential fix as outlined
> above?  I would really appreciate any help you can provide.
>
> Thanks
>
>
> This message is for the designated recipient only and may contain
> privileged, proprietary, or otherwise private information.  If you have
> received it in error, please notify the sender immediately and delete the
> original.  Any other use of the email by you is prohibited.

-- 
David Delbecq
Royal Meteorological Institute of Belgium

-
Is there life after /sbin/halt -p?

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Importing user-defined class in a JSP page

Posted by Anto Paul <an...@gmail.com>.
On 6/9/05, uttam.g.dubal@accenture.com <ut...@accenture.com> wrote:

> Any ideas how to import a user-defined class in JSP, I mean where to
> place the class file and is there anyother environment variable to set?
> I read somewhere that if you are using jdk 1.4 and above, you need to
> have package name for classes.  It said to Put your webappname class in
> a package, compile it and then import it like the following in your JSP
> file:  <%@ page import="packagename.WebAppName"%>
> 

You should grab some good book on programming JSP and Servlets.

    I assume you know Java.  As far as the error is concerned it don't
seem to be because of a class is not properly imported. The syntax for
importing class in JSP page is correct assuming WebAppName is the
class you are importing. The compiles class files in the proper
package structure is to be put in
$CATALINA_HOME/webapps/mywebapp/WEB-INF/classes folder. Then restart
Tomcat.

    You can find a sample web application in the
$CATALINA_HOME/webapps/examples folder.
-- 
rgds
Anto Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org