aspose file tools*
The moose likes JSP and the fly likes need urgent help on JSP and XMl PLEASE!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "need urgent help on JSP and XMl PLEASE!!!!!!" Watch "need urgent help on JSP and XMl PLEASE!!!!!!" New topic
Author

need urgent help on JSP and XMl PLEASE!!!!!!

midan myaa
Greenhorn

Joined: Nov 26, 2001
Posts: 8
Hi i have a DomBean file and a Question file and i want to parse the xml file to the Questions class so that i can call the properties of the Questions class in a jsp
-------------------------------------------------------------------------
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import org.xml.sax.*;

public class DOMBean implements java.io.Serializable {
public DOMBean() {
}
public static Document getDocument(String file) throws Exception {
// create a DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// create a DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();
// parse the input file to get
// a Document object
Document doc = db.parse(new File(file));
return doc;
}
}

-------------------------------------------------------------------------
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import org.xml.sax.*;

public class Question {
String questionText, answer;
public Question()
{
NodeList textList = question.getElementsByTagName("questionText");
Element textNode = (Element) textList.item(0);
questionText = ((Text) textNode.getFirstChild()).getData();
NodeList answerList = question.getElementsByTagName("answer");
Element answerNode = (Element) answerList.item(0);
answer = ((Text) textNode.getFirstChild()).getData();
}
public String getQuestionText(){
return questionText;
}
public String getAnswer(){
return answer;
}
}
-------------------------------------------------------------------------
I have written a jsp file when i was testing which works
<%@ page contentType="text/html"%>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="Dombean.*" %>
<%! String questionText; %>

<jsp:useBean id="domparser" class="Dombean.DOMBean" />
<%
Document doc = domparser.getDocument("C:\\Tomcat\\FYProject\\lib\\Questions.xml");
NodeList textList = doc.getElementsByTagName("questionText");
Element textNode = (Element) textList.item(3);
questionText = ((Text) textNode.getFirstChild()).getData();
%>
<html>
<body bgcolor="#ffffcc">
<%= questionText %>
</body>
</html>
but i just want to use the jsp file to call the questionText and answer strings from the Question class.......can anyone help me with this
thanx
 
Consider Paul's rocket mass heater.
 
subject: need urgent help on JSP and XMl PLEASE!!!!!!