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

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

 
midan myaa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic