Classes and JSPs in Tomcat-4.1.24
Where to put the class files and how to call them in the jsps in Tomcat-4.1.24.
<br>In Tomcat-3.2.4 I used to put them in WEB-INF/classes and call them. The same jsp's working in Tomcat-3.x are not working in 4.1.24 version. Any idea???
Thanx in advance
Apparently tomcat4.1 requires all class files to be in a package so class files that you just had in WEB-INF/classes need to be re-compiled into packages.
Then you will need to import these classes into your jsp with a
<%@ page import= ..../> statement
Similar Messages
-
Unable to compile class for JSP. apache-tomcat-6. What could be wrong?
Hello, I am new to JSP and I am trying a very basic jsp and class file on Windows XP. I get the Unable to compile class for JSP.
Steps that I have done:
javac ch06_01.java , placed the ch06_01.class under
C:\Apps\apache-tomcat-6.0.16\webapps\ch06\WEB-INF\classes
Then grabbed the ch06_02.jsp and placed it under
C:\Apps\apache-tomcat-6.0.16\webapps\ch06\
When I run it (by placing this into Explorer or Firefox URL
http://localhost:8080/ch06/ch06_02.jsp) I get the error further
below. Things I have done and made sure they are in place are:
set up JAVA_HOME to C:\Apps\jdk1.6.0_06
Using CATALINA_BASE: C:\Apps\apache-tomcat-6.0.16
Using CATALINA_HOME: C:\Apps\apache-tomcat-6.0.16
Using CATALINA_TMPDIR: C:\Apps\apache-tomcat-6.0.16\temp
Using JRE_HOME: C:\Apps\jre1.6.0_06
I did a google on the error and I found people saying to place the
tools.jar from the jsk into the lib directory under CATALINA_HOME. But
the examples still don't work. What step could I be missing? Your help is greatly
appreciated.
This is the simple jsp file:
<%@ page import="ch06_01" %>
<HTML>
<HEAD>
<TITLE>Using a JavaBean</TITLE>
</HEAD>
<BODY>
<H1>Using a JavaBean</H1>
<% ch06_01 messager = new ch06_01(); %>
The message is: <%= messager.msg() %>
</BODY>
</HTML>
this is the simple ch6_01 java file:
public class ch06_01
public ch06_01()
public String msg()
return "Hello from JSP!";
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
The import ch06_01 cannot be resolved
An error occurred at line: 9 in the jsp file: /ch06_02.jsp
ch06_01 cannot be resolved to a type
6: <BODY>
7: <H1>Using a JavaBean</H1>
8:
9: <% ch06_01 messager = new ch06_01(); %>
10:
11: The message is: <%= messager.msg() %>
12:
An error occurred at line: 9 in the jsp file: /ch06_02.jsp
ch06_01 cannot be resolved to a type
6: <BODY>
7: <H1>Using a JavaBean</H1>
8:
9: <% ch06_01 messager = new ch06_01(); %>
10:
11: The message is: <%= messager.msg() %>
12:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Edited by: indikon1 on Jun 12, 2008 1:18 PM
I just updated the directories of the variables to reflect the current status of my system.What is wrong is that you are using an "old" jsp tutorial :-)
Since Java 1.4, JSPs have been unable to access classes in the "default" package.
What you need to do:
Put the java class ch06_01 in a package.
Steps to do this
- Edit ch06_01 and add the following to the very top of the file (without the quotes): "package mypackage;"
- create a folder "mypackage"
- move ch06_01.java into that folder
- compile that class (now in the mypackage package)
- place ch06_01.class under C:\Apps\apache-tomcat-6.0.16\webapps\ch06\WEB-INF\classes\mypackage
In your jsp:
<%@ page import="mypackage.ch06_01" %>
I would suggest using a more up-to-date tutorial that uses JSTL.
Take a look at this [Apache Tomcat tutorial|http://www.coreservlets.com/Apache-Tomcat-Tutorial/index.html] -
Unable to compile class for JSP in tomcat
Hi
I developed an application. it works Ok in embedded OC4J server. But I get the following error when I deployed to tomcat server :
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:157)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:332)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
I followed the steps of deploying exactly as Oracle developer guide and I don't know what is the reason of this error
please how can I solve this problemHi
16-Jan-2007 04:09:17 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:933)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
at org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:219)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
at oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:157)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:332)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595) -
Accessing java class in JSP on Tomcat 5.5 server
Just i want to use a java class in JSP.
Explanation in following steps :
a. MY JSP Code - SimpleBean.jsp
b. My Java file - test.java
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
d. Environment Variables
e. Error Message faced
Now Brief explanation.
a. MY JSP Code :
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,test" errorPage="" %>
<td>
<%! test obj = new test();
obj.setAge(32); %>
<%= obj.getAge(); %>
</td>
b. My Java file - test.java
package test;
class test
private int age;
public int getAge()
return age;
public void setAge(int intage)
this.age = intage;
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
Tomcat Root : c:\Program Files\apache\tomcat5.5\webapps\ROOT
jdk : C:\Program Files\Java\jdk1.5.0\bin;
jre : C:\Program Files\Java\jre1.5.0\bin;
test.java : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\test.java
SimpleBean.jsp : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\SimpleBean.jps
d. Environment Variables :
PATH :
C:\Program Files\Java\jdk1.5.0\bin; C:\Program Files\Java\jre1.5.0\bin;
CLASSPATH :
.;C:\Program Files\Java\jre1.5.0\bin;
e. Error Message Faced : ( on accessing url http://localhost:8080/NRMS/SimpleBean.jsp )
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
The import test cannot be resolved
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved (or is not a valid type) for the field SimpleBean_jsp.obj
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved or is not a type
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token "32", delete this token
An error occurred at line: 28 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token ";", delete this token
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:389)
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.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.
Apache Tomcat/5.5.4
Please explain where i am doing the mistake.
Thanks in advance.
Regards,
Lax.>
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="java.sql.*,test" errorPage=""
%>Your class is test.test.The compiler wouldnt know what test is from your import.
Change import as
java.sql.*,test.test
<%! test obj = new test();
obj.setAge(32); %>The symbol '!' ? -
Java Classes and JSP`s (urgent)
hi, my question is:
How can i invoke normal java classes` methods using Jsp`s for this??, is it possible??, if it is, then how do you do this, and where do you have to put the java classes in order to find them from a jsp.
thanksHi,
You can access normal java classes in JSP pages. You have to import them in the header like this:
<%@ page language="java" import="//your java class file with package"%>
or if u r using java beans, then use the <usebean> tag. Put the java classes in the classes directory. Which server u r using? If it is JWS, then u have a specified classes directory, where u have to put all the class files along with their packages. Hope this will help.
atanu. -
Tomcat BasicDataSource class and JSP
HiFriends,
I am trying to run this simple jsp example:
<%@ page language="java" import="java.sql.*,javax.naming.InitialContext,javax.naming.Context,javax.sql.DataSource,org.apache.commons.dbcp.BasicDataSource" %>
<body bgcolor="white">
<font color="red">
<%
Connection conn = null;
try {
InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:comp/env");
DataSource ds = (DataSource)context.lookup("jdbc/juddidb");
out.print(" DriverClassName: " + ((BasicDataSource) ds).getDriverClassName());
out.print(" Url: " + ((BasicDataSource) ds).getUrl());
out.print(" Username: " + ((BasicDataSource) ds).getUsername());
out.print(" Password: " + ((BasicDataSource) ds).getPassword());
out.print(" MaxActive: " + ((BasicDataSource) ds).getMaxActive());
out.print(" MaxWait: " + ((BasicDataSource) ds).getMaxWait());
out.print(" NumActive: " + ((BasicDataSource) ds).getNumActive());
out.print(" numIdle: " + ((BasicDataSource) ds).getNumIdle());
} catch (Exception e) {
e.printStackTrace();
%>But its giving me the following errors:
exception
javax.servlet.ServletException: org/apache/jsp/test_jsp (wrong name: org/apache/jsp/Test_jsp)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: org/apache/jsp/test_jsp (wrong name: org/apache/jsp/Test_jsp)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
java.net.URLClassLoader.access$100(URLClassLoader.java:56)
java.net.URLClassLoader$1.run(URLClassLoader.java:195)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:156)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:548)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:136)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:307)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Can someone please tell meif I have to set any classpath for the BasicDataSource class????exception
javax.servlet.ServletException:
org/apache/jsp/test_jsp (wrong name:
org/apache/jsp/Test_jsp)
org.apache.jasper.servlet.JspServlet.service(JspServl
et.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:802)
root cause
java.lang.NoClassDefFoundError:
org/apache/jsp/test_jsp (wrong name:Something suggests me that this has nothing to do with the CLASSPATH, but simply the JSP name. I think there is a problem with the name you specified in the URL. Case-sensitivity might matter.
Just trying to guess!
Rich. -
Problem with JNDI and JSP in Tomcat
Hi,
Basically, what I've done is to use the Tomcat administration web
application to create the DataSource, which looks like it populated the
server.xml (see below). I then try to access the testconn.jsp, and am
getting that "Name java:comp is not bound in this Context" error.
I was wondering if anyone could tell me what I'm doing wrong?
Thanks,
Feri
My Configuration:
- Tomcat 5.0.19
- MySQL 4.0.18-nt
- mysql-connector-java-3.0.15-ga-bin.jar
server.xml:
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<!--Feri test JNDI-->
<Context crossContext="true" debug="5" docBase="injury" path="/injury" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_injury_log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/injury" auth="Container"
type="javax.sql.DataSource">
</Resource>
<ResourceParams name="jdbc/injury">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>root</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/injury</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
</ResourceParams>
</Context>
<!--Feri test JNDI end-->
</GlobalNamingResources>
\webapps\injury\WEB-INF\web.xml:
<resource-ref>
<description>Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file.</description>
<res-ref-name>jdbc/injury</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
\webapps\injury\testconn.jsp
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ taglib prefix="ct" uri="/injury" %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<h1>Connection test</h1>
<ct:connection name="jdbc/injury">
<%
Statement stmt= conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery("select * from user");
while (rs.next()){
%><%=rs.getString(1)%><%=rs.getInt(2) %><br><%
rs.close();
stmt.close();
%>
</ct:connection>
ConnectionTag.java
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.naming.*;
import javax.sql.*;
import javax.sql.DataSource;
public class ConnectionTag extends TagSupport implements TryCatchFinally {
private Connection conn;
// JNDI name of the connection
private String name;
public void setName(String name)
this.name = name;
public int doStartTag()
throws JspException
try {
Context env = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) env.lookup(name);
if (ds != null)
conn = ds.getConnection();
} catch (Exception e) {
throw new JspException(e);
if (conn == null)
throw new JspException("can't open connection " + name);
pageContext.setAttribute("conn", conn);
return EVAL_BODY_INCLUDE;
public void doCatch(Throwable t)
throws Throwable
throw t;
public void doFinally()
try {
Connection conn = this.conn;
this.conn = null;
pageContext.removeAttribute("conn");
conn.close();
} catch (Exception e) {
Tomcat 5.0\conf\Catalina\localhost\injury.xml
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Injury" docBase="E:\Tomcat 5.0\webapps\injury" path="/injury" className="org.apache.catalina.core.StandardContext"
cachingAllowed="true" charsetMapperClass="org.apache.catalina .util.CharsetMapper" cookies="true" crossContext="false" debug="0"
mapperClass="org.apache.catalina.core.StandardContextMapper" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper" >
<Resource auth="Container" description="Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file." name="jdbc/injury" type="javax.sql.DataSource"/>
<ResourceLink global="jdbc/injury" name="injury" type="javax.sql.DataSource"/>
</Context>Hi,
First of all, you can find alot of information about this in the forum about jsp's.
I think a good thing to do is not to put your context tag directly into the server.xml file.
What you should do is create a context.xml file with the context-tag in it, and put it in the META-INF directory of your .war file. Upon deployment to tomcat5 this file will be extracted from the war, copied to the conf\enginename\hostname directory, and it will be renamed to contextName.xml.
I think you are developing directly into the webapps directory, and I believe you should avoid that and use the deployment feature of the manager web-app or you should use the deployertool from you ide or standalone ant.
anyway, for starters try to remove the context tag from the server.xml file as described above, and check out the jsp / jdbc forums for simular problems and answers.
good luck -
Hi everyone,
I build a class in java, and now i wanna use this class in my jsp file.
I put that class into web-inf/classes in Apache Tomcat, but don't work.... Anyone can help me?
Greetings!Put the class with its package such as com.sun.ejb.MyClass
-- > /WEB-INF/classes/com/sun/ejb/MyClass.class
then use it
http://www.skillipedia.com -
Ordinary java class and jsp page
hi i want to use some java class(not javabean ) in my jsp . how do i import them and use them?
You can just import the package into your JSP, and access it like any other class of the Standard Java API that you access.
fun_one -
Hi
I'm working on a tool wich can be used by different type of users. For example Employee, Administrator and Manager.
So I thought I could create an abstract class User with subclasses employee, administrator and manager
So depending on who logs on you could initiate the user:
user = new Employee()
However I'm not cuite sure how this works in JSP
Is there a way to do this in the jsp:useBean tag or somewhere else?
thx BabetteYou might want to check out the Delegation Pattern. Its for exactly this case.
What happens if a Manager is also an Administrator? Do you give him two seperate logins to the system?
Most likely you just want a user object, and assign the users "roles"
One thing about the useBean tag it can take both a type and a class attribute:
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1217.html#8865
Class is the actual class of the object to instantiate
Type is the type of object to declare it as - ie either a superclass or interface
<jsp:useBaen name="user" class="com.Employee" type="com.User"/>
Would generate code equivalent to
User user = new Employee().
Cheers,
evnafets -
Passing vector between java class and jsp page
Hi,
I think this is similar to the last post but anyways maybe somebody can help us both out bontyh.....I am getting an error saying undefined variable or class when i try to access a Vector which was returned in a class.
Anyways anyone got any ideas?Maybe if you give some more information...
-
Can not call bean class from JSp/Tomcat 5.5
hello everyone...
i m using one bean class Parser which is called by discussion.jsp page. i put class file in webapps/grid/WEB-INF/classes and JSP page is in webapps/grid/. The whole combination is working fine for tomcat 3.3.2 but not working properly in tomcat 5.5.
Error is as follow...
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 38 in the jsp file: /discussion.jsp
Generated servlet error:
Parser cannot be resolved or is not a typeplease help me....
Thank in AdvanceYou still need to import the class from the default package. As a word of advice you should put the class in a package. The later versions of Tomcat do not play well with bean classes that are not in packages.
-
Problem importing classes and beans
Hey there. Im having one major fustrating problem! When I code supporting classes and beans for my JSPs I get a code 500 internal server error when trying to import (via <%@ page import="class" %> and <jsp:useBean/>) Im storing my classes and beans in the WEB-INF folder and the calling JSPs are located in /ROOT/tests/8/jsp.jsp. Im using the following to import a class or bean:
<%@ import="aClass" %>
Seen as tho its in the WEB-INF folder I won't have to explicitly refer to where the class is located, just the class name.
I never had this problem when I was using my hosting service. Its only on my localhost server in which I get the Internal Server error.
Help appreciated, thx.
PS: Im quite new to JSP/Java Servlet.import (via <%@ page import="class" %> and
<jsp:useBean/>) Im storing my classes and beans in the
WEB-INF folder try put your class file in WEB-INF/classes.
or first put bean in the package, like WEB-INF/classes/packagename/beanclass
in jsp page:
<jsp:useBean id="Mybean" class="packagename.beanclass" scope="request" />
Question: is /ROOT a context entry in your server.xml?
Which JSP Container (version) you use? Maybe your localhost server's set up is different with your hosting. -
Tomcat 4.1 Bean error (Unable to compile class for JSP)
Help,
I am using Tomcat 4.1 with with JDK1.3.1_01. I have a JSP page in which I try to use a Bean, but I get the following error from Tomcat.
The JSP page is very simple. I am using package names in the import statement. Code below.
I've put the class files under
<TOMCAT>\webapps\projectname\WEB-INF\classes under the appropriate packages. What else is missing? I can not figure out what I am doing wrong.
***************** START JSP CODE *********************
<html>
<head>
<title>User Information</title>
</head>
<%@ page session="true" %>
<%@ page import="com.xxx.yyy.data.*" %>
<body>
<P> </P>
<P> </P>
<P> </P>
<!--
<jsp:useBean id="user" class="com.xxx.yyy.data.User" scope="session"/>
-->
<%
User user = (User) session.getAttribute("user");
%>
UserID = <%= user.getUserID() %><BR>
User Name = <%= user.getUserName() %><BR>
Password = <%= user.getPassword() %><BR>
Password Hint = <%= user.getPasswordHint() %><BR>
</body>
</html>
***************** END JSP CODE *********************
***************** START TOMCAT ERROR MESSAGE *********************
org.apache.jasper.JasperException: Unable to compile class for JSP
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:477)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:182)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2397)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 20 in the jsp file: /userInfo.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:7: package com.xxx.yyy.data does not exist
import com.xxx.yyy.data.*;
^
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:61: package com.xxx.yyy.data does not exist
com.xxx.yyy.data.User user = null;
^
An error occurred at line: 20 in the jsp file: /userInfo.jsp
Generated servlet error:
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:63: package com.xxx.yyy.data does not exist
user = (com.xxx.yyy.data.User) pageContext.getAttribute("user", PageContext.SESSION_SCOPE);
^
An error occurred at line: 20 in the jsp file: /userInfo.jsp
Generated servlet error:
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:66: package com.xxx.yyy.data does not exist
user = (com.xxx.yyy.data.User) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.xxx.yyy.data.User");
^
An error occurred at line: 25 in the jsp file: /userInfo.jsp
Generated servlet error:
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:77: cannot resolve symbol
symbol : class User
location: class org.apache.jsp.userInfo_jsp
User user = (User) session.getAttribute("user");
^
An error occurred at line: 25 in the jsp file: /userInfo.jsp
Generated servlet error:
D:\Apache_Group\Tomcat_4.1\work\Standalone\localhost\PALBO\userInfo_jsp.java:77: cannot resolve symbol
symbol : class User
location: class org.apache.jsp.userInfo_jsp
User user = (User) session.getAttribute("user");
^
6 errors
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:315)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:326)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:182)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2397)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
at java.lang.Thread.run(Thread.java:536)
***************** END TOMCAT ERROR MESSAGE *********************Hi
I am running my Tomcat apps (on a Windows dev machine) in an alternate location (ie. not default webapps). The same crap comes to me every time. Unable to install etc. I have tried every trick in the book regarding classpath settings etc.
When I use 'javap' to check the classpath from any location on my machine, its works and javap returns the signature of my class.
When I use it though Tomcat (with the import set to include the filename), it get the error. I have heard rumors that using JDK 1.3 in stead of 1.4 helps, but I just want it to work with 1.4 :)
So if any of you can help me on this, please.
PS. On my linux server it works just fine, as does every other thing on that machine ;)
Chris (chris.schuit <at> euronet.nl) -
Importing class in a jsp using Tomcat
Hello All,
Using Tomcat:
I have class here:
examples/WEB-INF/classes/ package/myclass.class
I have a .jsp here:
examples/JSPFolder/myjspfile.jsp
I want to import the class into the jsp.
I have tried the following combinations of importy lines based on previous posts on these boards and each have failed with same error:
Unable to load class for JSP
<%@ page import="myclass" %>
<%@ page import="myclass.*" %>
<%@ page import="package.myclass" %>
<%@ page import="package.myclass.*" %>
<%@ page import="WEB-INF/classes/package/myclass%>
I have seen a number of posts for this same problem, and have tried those solutions as well, but none work. I am sure that this is simply a problem of finding the right directory, as I can successfully run the .jsp file iwhen I remove the import line.
Can someone please help?There is a folder for shared packages
tomcat_root\lib; or
tomcat_root\common
also most versions have a lib or common folder for each webapp for packages that are not to be shared.
tomcat_root\webapps\appname\web-inf\lib
Agreed that it is strange to allow servlets to import from the classes foler but not JSPs. It should make no difference but it is convension to place single classes in the same folder as the app's directory and packages (especially jar's) in the lib directory.
Maybe you are looking for
-
When Purchase Requistion?.
Hi, I am learning to create purchase orders. I found out that to begin creating with purchase order. I first need to do purchase requisition. I go to ME51 and create purchase requisition and use the following fields mentioned here http://help.sap.com
-
How to keep the overall sales price same after basic material cost changes
We have a below requirement from clientu2026 Sales Order with quantity 100 created. Letu2019s say the Basic material cost is $10 each and after the pricing procedure of SD (i.e taking condition types etc in account) overall sales order price came to
-
Hi, Can anyone help me on this- I have a symbol in my stage. He is masked by a circle. I want that when I click on the Symbols, the mask expands and reveals what is behind it. Like this : I followed the threat "I want to know how masking objects or
-
Why Do BT use DLM? it just drives some people away...
Hello.Ive emailed a few depts in BT.When I first got broadband I ofc went with BT was told at the time I would get around 4.5mb It turned out to be a lot less than that (3mb)because of the distance from the Exchange my downstream atten runs around 47
-
Limits to recognized size of 2nd hard disk
I just installed a Seagate 250 gb ST3250823A internal hard disk that is only recognized as a 128 gb disk. Is this a system limitation, and if so is there a fix to access the remaining available capacity? I have a 200gb firewire disk that is fully rec