File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JDOM works normally not with JSP" Watch "JDOM works normally not with JSP" New topic
Author

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);
try
{
//Output the new document to System.out
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, System.out);
}
catch(Exception e)
{
System.out.println(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="java.io.*,org.jdom.*,org.jdom.input.SAXBuilder"%>
<%
SAXBuilder builder =new SAXBuilder("org.apache.xerces.parsers.SAXParser");
Document l_doc=builder.build(new File("c:/message.xml"));
%>
<html>
<body>
<%=l_doc.getRootElement().getChild("message").getText() %>
</body>
</html>
Error Says
org.apache.jasper.JasperException: Unable to compile class for JSP
c:\j2sdkee1.3.1\repository\ucl31-wcsu\web\jdomnew\jdom$jsp.java:4: Package org.jdom not found in import.
import org.jdom.*;
^
c:\j2sdkee1.3.1\repository\ucl31-wcsu\web\jdomnew\jdom$jsp.java:5: 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.
regards
maulin.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
btw,
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...
regards
maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDOM works normally not with JSP