wood burning stoves 2.0*
The moose likes JSP and the fly likes How to change this java file into jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to change this java file into jsp?" Watch "How to change this java file into jsp?" New topic
Author

How to change this java file into jsp?

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Hi, I am a beginner of Java and Jsp. Could You please tell me, How to convert the below java file into jsp file.

Thanks for responsing.

package parserexamples;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Vector;

// JAXP
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

// DOM
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import org.xml.sax.InputSource;


public class Check{
public static void printNode(Node node, String indent) {

switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
NodeList nodes = node.getChildNodes();
if (nodes != null) {
for (int i=0; i<nodes.getLength(); i++) {
printNode(nodes.item(i), "");
}
}
break;

case Node.ELEMENT_NODE:
String name = node.getNodeName();
for (int i=0; i<attributes.getLength(); i++) {
Node current = attributes.item(i);
}





// recurse on each child
NodeList children = node.getChildNodes();
if (children != null) {
for (int i=0; i<children.getLength(); i++) {
printNode(children.item(i), indent + " ");

}
}


break;

case Node.TEXT_NODE:
System.out.println("Node.TEXT_NODE");
break;
}

}

public static void main(String[] args) {

ile xmlFile = new File("C:/Documents and Settings/edward/Desktop/Role.xml");
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(false);

DocumentBuilder builder = factory.newDocumentBuilder();
System.out.println();

Document doc = builder.parse(xmlFile);

Node node = doc;
printNode(doc, "");
System.out.println("\n");
} catch (ParserConfigurationException e) {
System.out.println("The underlying parser does not support " +
"the requested features.");
e.printStackTrace();
} catch (FactoryConfigurationError e) {
System.out.println("Error occurred obtaining Document Builder " +
"Factory.");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

}

Thanks for responsing.


Thank You<br />Edward
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Why would you do a thing like that?

The file you posted desn't seem to have anything to do with generatng a view.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

edward durai,
Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Actually The above program is using to get the xml files each node names and node value.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

OK, so I ask again. What does this type of processing have to do with JSP?
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
actually my xml looks like

<fieldid>
<field f_id="0" sortingorder="3"/>
<field f_id="1" sortingorder="1"/>
<field f_id="2" sortingorder="2"/>
</fieldid>

i want to fetch the order only. ok. That's why I am using the above program. And it should work for both ie and firefox.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

edward, you're still not answering Bear's question It's an important one.


[My Blog]
All roads lead to JavaRanch
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Pardon me,I could not understand, what you are asking
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Building an XML document is not view manipulation.
This is not something you would ever want to do in a JSP.

Bear's question was very simple.
Why would you want to convert something like this into a JSP?
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Edward, it sounds like you want to read an xml file and display it in the browser.

Is this correct?

If so, a more proper way to do this (and what Bear and Ben are hinting at) is to create a servlet. Especially for the part that reads the xml file.

Is this an academic exercise where you were told to write a JSP?
[ August 26, 2006: Message edited by: Scott Johnson ]
 
jQuery in Action, 2nd edition
 
subject: How to change this java file into jsp?
 
Similar Threads
How to retrieve CDATA Section
Delete elements from XML file using DOM and java
XML Parsing problem
Building XML
parsing the XML tags values having the same name