• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change this java file into jsp?

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you do a thing like that?

The file you posted desn't seem to have anything to do with generatng a view.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually The above program is using to get the xml files each node names and node value.

Thanks
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so I ask again. What does this type of processing have to do with JSP?
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
edward, you're still not answering Bear's question It's an important one.
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pardon me,I could not understand, what you are asking
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic