奇怪的错误?

03-02-18 SR

一个servlet调用javabean的例子.单独调试javabean是好的.可是被servlet调用时方法里面出错.请各位高手指点迷津....

---------------------javabean--------------------------------------------

package xmlproject;

import org.dom4j.Document;

import org.dom4j.DocumentHelper;

import org.dom4j.Element;

public class Dom4jTest {

public Dom4jTest() {

}

//这个方法产生xml.

public Document createDocument() {

//被servlet调用时执行到这步出错说找不到DocumentHelper.createDocument()

//可是用其它javabean调用时却没有这个错误.真怪.

Document document = DocumentHelper.createDocument();

Element root = document.addElement( "学生花名册" );

Element author1 = root.addElement( "学生" )

.addAttribute( "性别", "男" );

Element aut_son1=author1.addElement("姓名").addText("jinsanqi");

Element aut_son2=author1.addElement("年龄").addText("20") ;

Element aut_son3=author1.addElement("电话").addText("8801245") ;

return document;

}

public void test(){

System.out.println("调用这个方法就不出错!");

}

public static void main(String [] args){

Dom4jTest dom4j=new Dom4jTest();

Document doc=dom4j.createDocument() ;

String str=doc.asXML() ;

System.out.println(str);

}

}

-----------------servlet------------------------------------------

package xmlproject;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import javax.xml.transform.stream.*;

import org.dom4j.Document;

import javax.xml.transform.*;

import org.dom4j.DocumentHelper;

public class succeed extends HttpServlet {

public void init() throws ServletException {

}

//Process the HTTP Get request

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

doPost(request,response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

try{

Dom4jTest dom4j=new Dom4jTest();

//调用这个方法不出错

dom4j.test() ;

//在这里调用时出错.但是调用其它javabean方法不出错.

Document doc=(Document)dom4j.createDocument() ;

String str=doc.asXML() ;

StreamSource xml = new StreamSource(new StringReader(str));

StreamSource xsl = new StreamSource("Inputxsl.xsl");

response.setContentType("text/html; charset=UTF-8");

StreamResult result = new StreamResult(response.getWriter());

Transformer trans = TransformerFactory.newInstance().newTransformer(xsl);

trans.setOutputProperty("encoding", "UTF-8");

trans.transform(xml, result);

}catch(Exception e){

}

}

//Clean up resources

public void destroy() {

}

}