File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes JDOM works normally not with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JDOM works normally not with JSP" Watch "JDOM works normally not with JSP" New topic

JDOM works normally not with JSP

riya s
Ranch Hand

Joined: Feb 28, 2003
Posts: 110
When I call this file from command prompt it works fine...
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
public class HelloJDOM
public static void main(String[] args)
//Create a root element for the document
Element root = new Element("Greeting");
root.setText("Hello World");
//Create a new document based on root
Document doc = new Document(root);
//Output the new document to System.out
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, System.out);
catch(Exception e)
ALL the org.jdom.* are found
When I use jsp and import the same they are not found...
<%@ page contentType="text/html" %>
<%@page import="*,org.jdom.*,org.jdom.input.SAXBuilder"%>
SAXBuilder builder =new SAXBuilder("org.apache.xerces.parsers.SAXParser");
Document File("c:/message.xml"));
<%=l_doc.getRootElement().getChild("message").getText() %>
Error Says
org.apache.jasper.JasperException: Unable to compile class for JSP
c:\j2sdkee1.3.1\repository\ucl31-wcsu\web\jdomnew\jdom$ Package org.jdom not found in import.
import org.jdom.*;
c:\j2sdkee1.3.1\repository\ucl31-wcsu\web\jdomnew\jdom$ Class org.jdom.input.SAXBuilder not found in import.
import org.jdom.input.SAXBuilder;
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Priya
from command prompt it will work as you might have the CLASSPATH properly set but when you are using JSP then you have to put those JDOM classes (jar files or whatever you have) in the WEBSERVER'S CLASSPATH.
seems you are on Tomcat. you have to add the JDOM classes in Tomcat's classpath and you can do it by adding those jars to - setclasspath.bat (on Windows)...
hope you get somewhere with this pointer.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
u can find this setclasspath.bat in YOUR_TOMCAT_HOME\bin directory.
this batch file is used by catalina.bat which you might be using to run Tomcat...
I agree. Here's the link:
subject: JDOM works normally not with JSP
It's not a secret anymore!