Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDOM works normally not with JSP

 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic